Merhaba dostlar daha önce sormuştum ama cevap alamamıştım tam olarak.
Tekrardan sizlere danışayım dedim.
Aşağıda ki gibi bir Laravel servisimiz mevcut.
Fakat indirim kodu uygulandığı zaman resimde ki gibi tek bir ürüne uyguluyor bu iskontoyu.
Halbuki total de ödenen ücret olması lazım ve o 2 ürünün toplamına uygulanması gerekiyor bu indirim kodunun.
bu kodlar da nerede hata yapılmış olabilir acaba
https://prnt.sc/EK-IA6NsLA5p
private function buildInvoice(Payment $payment, $lines, $eInvoiceUser)
{
$address = $payment->invoiceAddress;
$user = $payment->user;
$addressBook = new AddressBookModel();
$addressBook->setIdentificationNumber($address->tax_number);
$addressBook->setName($address->is_company ? $address->company_name : $address->first_name);
$addressBook->setReceiverPersonSurName($address->last_name);
$addressBook->setReceiverStreet($address->address);
$addressBook->setReceiverDistrict(optional($address->district)->name);
$addressBook->setReceiverCity(optional($address->city)->name);
$addressBook->setReceiverCountry('tr');
$addressBook->setReceiverPhoneNumber($address->phone_number);
$addressBook->setReceiverEmail($user->email);
$addressBook->setReceiverTaxOffice($address->tax_office);
$generalInfo = new GeneralInfoModel();
$generalInfo->setInvoiceProfileType($eInvoiceUser ? InvoiceProfileType::COMMERCIAL : InvoiceProfileType::ARCHIVE);
$generalInfo->setIssueDate(now());
$generalInfo->setCurrencyCode('TRY');
// $generalInfo->setPrefix('TC6');
$generalInfo->setExchangeRate(1);
$generalInfo->setTotalAmount($payment->price);
$generalInfo->setType(1);
$eArchiveInfo = new EArchiveInfoModel();
$eArchiveInfo->setSendEmail(true);
$eArchiveInfo->setAllowOldEArsivCustomer(false);
$invoiceLines = [];
foreach ($lines as $lineKey => $line) {
/** @var PaymentProduct $paymentProduct */
$invoiceLine = new InvoiceLineModel();
$invoiceLine->setDisableVatExemption(true);
$invoiceLine->setInventoryCard($line->product->name);
$invoiceLine->setAmount($line->qty ? $line->qty : 1);
$invoiceLine->setUnitPrice($line->item_data['main_price']);
$invoiceLine->setUnitCode('C92');
$invoiceLine->setVatRate($line->tax);
$invoiceLine->setLineAmount($line->grand_total);
$amount = $line->grand_total;
$totalDiscountAmount = 0;
if ($line->discount) {
$totalDiscountAmount = $line->discount;
$invoiceLine->setDiscountAmount($line->discount);
$invoiceLine->setDiscountRate($line->discount * 100 / $amount);
}
if($line->discountCode) {
$price = $line->item_data['main_price'];
if( $line->item_data['discount_type'] == '%' ) {
$discountTotal = ($price * $line->discountCode->amount) / 100;
$totalDiscountAmount = $discountTotal;
$invoiceLine->setDiscountAmount($discountTotal);
$invoiceLine->setDiscountRate($line->discountCode->amount);
}else if( $line->item_data['discount_type'] == 'TL' ) {
$totalDiscountAmount = $line->discountCode->amount;
$invoiceLine->setDiscountAmount($line->discountCode->amount);
$discountRate = (100 * $line->discountCode->amount) / ($price + $line->discountCode->amount);
$invoiceLine->setDiscountRate($discountRate);
}
}
if($line->wallet_status) {
$price = $line->item_data['main_price'];
$totalDiscountAmount = $totalDiscountAmount + $line->wallet_status;
$discountRate = (100 * $totalDiscountAmount) / ($price + $totalDiscountAmount);
$invoiceLine->setDiscountAmount($totalDiscountAmount);
$invoiceLine->setDiscountRate($discountRate);
}
// $subtotal = $amount - $line->grand_total;
$invoiceLines[] = $invoiceLine->getJsonObject();
}
$req = new CreateOutboxInvoiceModel();
$req->setAddressBook($addressBook->getJsonObject());
$req->setGeneralInfoModel($generalInfo->getJsonObject());
$req->setInvoiceLines($invoiceLines);
$req->setIsNew(true);
$req->setXsltCode('master');
$req->setStatus(TurkcellStatus::DRAFT);
$req->setUseManualInvoiceId(false);
$req->setIsSend(false);
$req->setEArchiveInfoModel($eArchiveInfo->getJsonObject());
// $req->setNote($payment->header->description);
return $req;
}