not->toBeFalse(); $content = (string)$content; $start = strpos($content, 'public function addInvoicesToDraft'); $end = strpos($content, 'public function getLastEconomicTransferMetrics'); expect($start)->not->toBeFalse(); expect($end)->not->toBeFalse(); expect($end)->toBeGreaterThan($start); $methodBlock = substr($content, (int)$start, (int)$end - (int)$start); expect($methodBlock)->toContain('$order_objects = [];') // Bug #11 customer 35131752 — the customer discount is threaded through add_orders // so the line-level discountPercentage is applied to each line item. ->and($methodBlock)->toContain('$customer_discount_percentage = self::resolveCustomerDiscountPercentageForDraft') ->and($methodBlock)->toContain('$metrics = (new economic())->invoices->draft->add_orders(') ->and($methodBlock)->toContain('$customer_discount_percentage') ->and($methodBlock)->toContain('...$metrics') ->and($methodBlock)->not->toContain('self::addInvoiceToDraft($order[\'id\'], true, $draft_id, $currency);'); }); it('keeps single-order draft uploads as a wrapper around the batch endpoint', function (): void { $content = file_get_contents(dirname(__DIR__, 3) . '/modules/economic/endpoints/invoices/draft/economic_invoices_draft_endpoint.php'); expect($content)->not->toBeFalse(); $content = (string)$content; $singleStart = strpos($content, 'public function add_order'); $singleEnd = strpos($content, 'public function add_orders'); expect($singleStart)->not->toBeFalse(); expect($singleEnd)->not->toBeFalse(); expect($singleEnd)->toBeGreaterThan($singleStart); $singleBlock = substr($content, (int)$singleStart, (int)$singleEnd - (int)$singleStart); expect($singleBlock)->toContain('$this->add_orders($invoiceDraftId, [$order], $currency);'); $batchBlock = substr($content, (int)$singleEnd); expect($batchBlock)->toContain('$draftInvoice->flushLinesInBatches($line_batch_size);') ->and($batchBlock)->toContain('$draftInvoice->addOrderItemLines($order, $use_itemized_discounts, $customer_discount_percentage);') ->and($batchBlock)->toContain("'orders_with_invoice_lines' => \$orders_with_invoice_lines"); }); it('selects itemized discount mode for collected invoice batch transfers', function (): void { $content = file_get_contents(dirname(__DIR__, 3) . '/objects/collected_order_invoices_o.php'); expect($content)->not->toBeFalse(); $content = (string)$content; expect($content)->toContain('resolveInvoiceLayoutNumber') ->and($content)->toContain('invoice_discount_layout') ->and($content)->toContain('hasDiscountedIncludedInvoiceItems') ->and($content)->toContain('orderItemHasBillableDiscount') ->and($content)->toContain('$customer_discount_percentage'); }); it('includes collected invoice batch transfer metrics in queue results when available', function (): void { $content = file_get_contents(dirname(__DIR__, 3) . '/classes/economic_transfer_executor.php'); expect($content)->not->toBeFalse(); $content = (string)$content; expect($content)->toContain('$transfer_metrics = $collected_order_invoices->getLastEconomicTransferMetrics();') ->and($content)->toContain("\$result['economic_transfer_metrics'] = \$transfer_metrics;"); });