예제 #1
0
 public static function billdiscount($account_id, $for_month, $amount, $bill)
 {
     $bill_info = Billinformation::where('bill_no', $bill->bill_no)->get();
     foreach ($bill_info as $key) {
         $amount_id[] = $key->discount_id;
     }
     if (count($bill_info) == 0) {
         $amount_id[] = NULL;
     }
     $bill_amount = Discount::whereIn('id', $amount_id)->sum('amount');
     if ($bill->discount == $bill_amount) {
         return $bill_amount;
     } else {
         if ($bill->discount && $bill_amount == 0) {
             $discount = new Discount();
             $discount->account_id = $account_id;
             $discount->for_month = $for_month;
             $discount->amount = $amount;
             $discount->date = date('Y-m-d');
             $discount->remarks = "billdiscount retransaction";
             $discount->is_considered = 1;
             $discount->save();
             $bill_info = Discount::discounts($discount->id, $discount->account_id, $discount->for_month);
             return $discount->amount;
         } else {
             if ($bill->discount != $bill_amount) {
                 return false;
             }
         }
     }
 }