Пример #1
0
 /**
  * User get data of bill with products.
  */
 public function test_get_bill_with_products()
 {
     $bill = factory(\App\Bill::class)->create(['user_id' => $this->user->id, 'client_id' => $this->client->id]);
     factory(\App\BillProduct::class, 3)->create(['bill_id' => $bill->id, 'product_id' => factory(\App\Product::class)->create(['user_id' => $this->user->id])->id]);
     factory(\App\BillApplicationProduct::class, 4)->create(['bill_id' => $bill->id, 'product_id' => factory(\App\ApplicationProduct::class)->create()->id]);
     $this->actingAs($this->user)->get('/bills/' . $bill->id . '/get')->seeJson(['to_pay' => BillData::getBillToPay($bill->id), 'saved_money' => BillData::getBillSavedMoney($bill->id), 'total' => BillData::getBillPrice($bill->id), 'number_of_products' => BillData::getNumberOfProducts($bill->id)]);
 }
Пример #2
0
 /**
  * Make sure getPaymentTerm method works.
  */
 public function test_it_return_valid_bill_payment_term()
 {
     // Test with bill that has payment term
     $this->assertEquals(date('d-m-Y', strtotime($this->bill->payment_term)), BillData::getPaymentTerm($this->bill->id));
     // Test with bill that does not have payment term
     $bill = factory(\App\Bill::class)->create(['user_id' => $this->user->id, 'client_id' => $this->client->id, 'payment_term' => '']);
     $this->assertEquals(false, BillData::getPaymentTerm($bill->id));
 }
Пример #3
0
 /**
  * Update bill payment term.
  *
  * @param int $billId
  * @param string $paymentTerm
  * @return mixed
  */
 public static function updatePaymentTerm($billId, $paymentTerm)
 {
     $response = new AjaxResponse();
     // Check if bill exists and belongs to current user
     $bill = Auth::user()->bills()->where('id', $billId)->first();
     if (!$bill) {
         $response->setFailMessage(trans('bill.bill_not_found'));
         return response($response->get(), 404)->header('Content-Type', 'application/json');
     }
     Auth::user()->bills()->where('id', $billId)->update(['payment_term' => date('Y-m-d', strtotime($paymentTerm))]);
     $response->setSuccessMessage(trans('bill.payment_term_updated'));
     $response->addExtraFields(['payment_term' => date('d-m-Y', strtotime($paymentTerm)), 'payment_term_passed' => BillData::paymentTermPassed($billId)]);
     return response($response->get())->header('Content-Type', 'application/json');
 }