randomElement(['po', 'bill', 'so', 'retainer_invoice', 'invoice']); $customerId = $paymentFor === 'so' || $paymentFor === 'invoice' ? $customerRepositoryInterface->getRandomId() : null; $supplierId = $paymentFor === 'po' || $paymentFor === 'bill' ? $supplierRepositoryInterface->getRandomId() : null; $taxDeducated = (new TaxDeducatedAttr) ->setChartOfAccountId($chartOfAccountRepositoryInterface->getRandomId()) ->setAmount($faker->numerify("###")); $attr = (new PaymentAttr) ->setPaymentFor($paymentFor) ->setSupplierId($supplierId) ->setCustomerId($customerId) ->setChartOfAccountId($chartOfAccountRepositoryInterface->getRandomId()) ->setPaymentDate($faker->date()) ->setReference($faker->colorName) ->setNotes($faker->text()) ->setAmount($faker->numerify("####")) ->setTaxDeducatedAttr($faker->randomElement([ $taxDeducated, null ])); switch ($attr->getPaymentFor()) { case 'so': $arrs = []; $soId = $saleOrderRepositoryInterface->getRandomId(); for ($i=0; $i < $faker->numberBetween(1, 10); $i++) { $arrs[] = (new PaymentDetailAtrr) ->setSaleOrderId($soId) ->setPaymentAmount($faker->numerify("####")); $saleOrderRepositoryInterface->updateStatus($soId, "sent"); } $attr->setPaymentDetailAttrs($arrs); break; case 'retainer_invoice': $arrs = []; for ($i=0; $i < $faker->numberBetween(1, 10); $i++) { $invoiceId = $retainerInvoiceRepositoryInterface->getRandomId(); $arrs[] = (new PaymentDetailAtrr) ->setRetainerInvoiceId($invoiceId) ->setPaymentAmount($faker->numerify("####")); $retainerInvoiceRepositoryInterface->updateStatus($invoiceId, "sent"); } $attr->setPaymentDetailAttrs($arrs); break; case 'invoice': $arrs = []; for ($i=0; $i < $faker->numberBetween(1, 10); $i++) { $invoiceId = $invoiceRepositoryInterface->getRandomId(); $arrs[] = (new PaymentDetailAtrr) ->setInvoiceId($invoiceId) ->setPaymentAmount($faker->numerify("####")); $invoiceRepositoryInterface->updateStatus($invoiceId, "sent"); } $attr->setPaymentDetailAttrs($arrs); break; case 'po': $arrs = []; for ($i=0; $i < $faker->numberBetween(1, 10); $i++) { $poId = $purchaseOrderRepositoryInterface->getRandomId(); $arrs[] = (new PaymentDetailAtrr) ->setPurchaseOrderId($poId) ->setPaymentAmount($faker->numerify("####")); $purchaseOrderRepositoryInterface->updateStatus($poId, "received"); } $attr->setPaymentDetailAttrs($arrs); break; case 'bill': $arrs = []; for ($i=0; $i < $faker->numberBetween(1, 10); $i++) { $billId = $purchaseOrderRepositoryInterface->getRandomId(); $arrs[] = (new PaymentDetailAtrr) ->setBillId($billId) ->setPaymentAmount($faker->numerify("####")); $billRepositoryInterface->updateStatus($billId, "open"); } $attr->setPaymentDetailAttrs($arrs); break; default: break; } $paymentMadeFacade->handleSavePayment( $attr ); } } }