コード例 #1
0
 public function createInvoice(Buyerable $buyer, Supplier $supplier, array $carts, TransactionShipping $transactionShipping, $note = null, $status = 'unpaid')
 {
     $invoice = new Invoice();
     $invoice->code = $this->generateInvoiceNumber($supplier);
     $invoice->note = $note;
     $invoice->status = $status;
     $invoice->buyer()->associate($buyer);
     $invoice->transaction_shipping()->associate($transactionShipping);
     $invoice->save();
     foreach ($carts as $cart) {
         $product = $cart['product'];
         $invoice->details()->create(['name' => $product->name, 'description' => $product->description, 'quantity' => $cart['quantity'], 'price' => $product->price, 'product_id' => $product->id]);
     }
     return $invoice->load('details');
 }