Example #1
0
 /**
  * postPayment
  */
 public function postPayment()
 {
     $data = Input::all();
     //$data['paydate'] = strtotime($data['paydate']);
     //插入payments
     $payment = OrderPayment::create($data);
     $payments = OrderPayment::where('order_id', Input::get('order_id'))->get();
     return View::make('admin.orders.payment')->with('payments', $payments);
 }
Example #2
0
function GetLastInvoiceOrder($id)
{
    return \OrderPayment::where(function ($query) {
        $query->where('status', 2)->orWhereNull('payment_reff');
    })->where('order_id', $id)->orderBy('id', 'desc')->first();
}
Example #3
0
 /**
  * Get Invoice Info
  *
  * @param \Illuminate\Database\Eloquent\Model
  * @return array $data
  */
 protected function _getInvoiceInfo($orderPayments)
 {
     $data = [];
     foreach ($orderPayments as $payment) {
         $temp = (array) $payment;
         // get user info
         $temp['user_info'] = \User::find($payment->user_id);
         /**
          ** Menentukan date invoice used, expired date dan expired on dengan Carbon
          */
         // get date of invoice used
         if ($payment->used_start == null) {
             if ($payment->pickup_date == null) {
                 $temp['date_invoice_used'] = $payment->delivery_date;
             } else {
                 $temp['date_invoice_used'] = $payment->pickup_date;
             }
         } else {
             $temp['date_invoice_used'] = $payment->used_start;
         }
         // get expired date of invoice
         $temp['expired_date'] = \Carbon\Carbon::parse($temp['date_invoice_used'])->addDays(31);
         // get interval day to expired date
         $now = \Carbon\Carbon::parse(date('Y-m-d'));
         $temp['expired_on'] = \Carbon\Carbon::parse($temp['expired_date'])->diffInDays($now, false);
         // get stuff invoice
         $temp['stuff'] = \OrderStuff::where('order_id', $payment->order_id)->whereNull('return_schedule_id')->select(['type', \DB::raw("COUNT(*) jumlah"), \DB::raw("if(type = 'box','" . \Config::get('thankspace.box.price') . "','" . \Config::get('thankspace.item.price') . "') price"), \DB::raw("(COUNT(*) * if(type = 'box','" . \Config::get('thankspace.box.price') . "','" . \Config::get('thankspace.item.price') . "')) subtotal"), \DB::raw("GROUP_CONCAT(description SEPARATOR ',') barang "), \DB::raw("GROUP_CONCAT(id SEPARATOR ',') ids ")])->groupBy('type')->get()->toArray();
         // set input for new invoice
         $temp['new_invoice_input'] = ['payment_reff' => $payment->invoice_code, 'used_start' => $temp['expired_date']->format('Y-m-d')];
         foreach ($temp['stuff'] as $val) {
             $type = $val['type'];
             $temp['new_invoice_input'][$type] = $val['jumlah'];
         }
         // new invoice
         $temp['new_invoice'] = null;
         if ($temp['next_invoice'] != null) {
             $temp['new_invoice'] = \OrderPayment::where('code', $temp['next_invoice'])->first();
         }
         // push to array for return data
         array_push($data, $temp);
     }
     return $data;
 }