Ejemplo n.º 1
0
 public function destroy($id)
 {
     $reduction = Reduction::find($id);
     $receivable = Receivable::find($reduction->receivable_id);
     switch ($reduction->reductable_type) {
         case 'Discount':
             $receivable->billable += $reduction->reductable->nominal;
             $receivable->receivable += $reduction->reductable->nominal;
             $receivable->balance += $reduction->reductable->nominal;
             $receivable->save();
             break;
         case 'Charge':
             $receivable->receivable += $reduction->reductable->nominal;
             $receivable->save();
             break;
         case 'Promotion':
             if ($reductable->discount > 0.0) {
                 $receivable->billable += $reduction->reductable->discount / 100 * $reduction->receivable->total;
                 $receivable->receivable += $reduction->reductable->discount / 100 * $reduction->receivable->total;
                 $receivable->balance += $reduction->reductable->discount / 100 * $reduction->receivable->total;
                 $receivable->save();
             } else {
                 $receivable->billable += $reduction->reductable->nominal;
                 $receivable->receivable += $reduction->reductable->nominal;
                 $receivable->balance += $reduction->reductable->nominal;
                 $receivable->save();
             }
             break;
         case 'Voucher':
             if ($reductable->discount > 0.0) {
                 $receivable->billable += $reduction->reductable->discount / 100 * $reduction->receivable->total;
                 $receivable->receivable += $reduction->reductable->discount / 100 * $reduction->receivable->total;
                 $receivable->balance += $reduction->reductable->discount / 100 * $reduction->receivable->total;
                 $receivable->save();
             } else {
                 $receivable->billable += $reduction->reductable->nominal;
                 $receivable->receivable += $reduction->reductable->nominal;
                 $receivable->balance += $reduction->reductable->nominal;
                 $receivable->save();
             }
             break;
     }
     Reduction::destroy($id);
     Session::flash('message', 'Sukses Menghapus Potongan Biaya Bimbingan');
 }