Ejemplo n.º 1
0
 public static function boot()
 {
     parent::boot();
     //validation on create
     static::creating(function ($customer) {
         return $customer->isValid();
     });
     //This event will delete all related model in category model
     static::deleted(function ($cs) {
         //Deletes all customerlog related to a customer
         $c = $cs->customerlog()->lists('id');
         if (!empty($c)) {
             Customerlog::destroy($c);
         }
         //Deletes all Receipt related to a customer
         $r = $cs->receipt()->lists('id');
         if (!empty($r)) {
             Receipt::destroy($r);
         }
         //Deletes all Salelog related to a customer
         $s = $cs->salelog()->lists('id');
         if (!empty($s)) {
             Salelog::destroy($s);
         }
     });
     //validation on update
     static::updating(function ($customer) {
         //return $customer->isValid();
     });
 }
 private function _view()
 {
     $type = Input::get('type', 'created_at');
     $daterange = Input::get('record_range', '');
     //Session::put('ss_select_expen', $type);
     Larasset::start('header')->css('daterangepicker');
     Larasset::start('footer')->js('moment', 'daterangepicker');
     Larasset::start('footer')->js('dataTables-min', 'dataTables-bootstrap');
     $data['entries'] = Expenditure::with(array('user' => function ($q) {
         $q->select('id', 'name');
     }));
     //Is the person Admin or not
     if (User::permitted('role.admin') !== true) {
         $data['entries'] = $data['entries']->where('user_id', Auth::user()->id);
     }
     if ($daterange !== '' && strpos($daterange, '-') !== FALSE) {
         $fromandto = explode('-', $daterange);
         $from = $fromandto[0];
         $to_plus_1day = strtotime('now') - strtotime('yesterday') + strtotime($fromandto[1]);
         $to = date('Y/n/d', $to_plus_1day);
         $data['from'] = format_date2($fromandto[0]);
         $data['to'] = format_date2($fromandto[1]);
     } else {
         $to = date('Y/n/d', strtotime('today'));
         $from = date('Y/n/d', strtotime('first day of this month'));
         $data['to'] = format_date2($to);
         $data['from'] = format_date2($from);
     }
     $data['entries'] = $data['entries']->whereBetween('date', array(sqldate($from), sqldate($to)));
     //$data['entries'] = $data['entries']->orderby($type, 'desc')->paginate(10);
     $data['entries'] = $data['entries']->orderby('date', 'asc')->get();
     //dd($data['entries']->toArray());
     $saleslog = Salelog::whereBetween('created_at', array(sqldate($from), sqldate($to)))->select('unitprice', 'costprice', 'quantity', 'total_unitprice')->orderby('receipt_id', 'desc')->get();
     $profitmargin = 0;
     foreach ($saleslog as $field) {
         //tt( $field->total_unitprice - ( $field->costprice * $field->quantity ) , true);
         $profitmargin += $field->total_unitprice - $field->costprice * $field->quantity;
     }
     $data['profitmargin'] = $profitmargin;
     //tt($data);
     return $data;
 }
Ejemplo n.º 3
0
 private function _processHistory($id, $daterange)
 {
     Larasset::start('header')->css('daterangepicker');
     Larasset::start('footer')->js('moment', 'daterangepicker');
     if (strpos($daterange, '-') !== FALSE) {
         $fromandto = explode('-', $daterange);
         $from = sqldate($fromandto[0]);
         $to_plus_1day = strtotime('now') - strtotime('yesterday') + strtotime($fromandto[1]);
         $to = sqldate(date('Y/n/d', $to_plus_1day));
         $data['todate'] = $fromandto[1];
     } else {
         $from = sqldate(date('Y/n/d', strtotime('first day of this month')));
         $to = sqldate('+1day');
         $data['todate'] = $to;
     }
     $customerlog = Salelog::with(array('product' => function ($q) {
         $q->select('id', 'name', 'productcat_id')->with(array('categories' => function ($qr) {
             $qr->select('id', 'type');
         }));
     }))->where('customer_id', '=', $id)->whereBetween('created_at', array($from, $to))->orderBy('id', 'desc');
     //tt(groupThem($customerlog->get()->toArray(), 'receipt_id'));
     $customerDetails = Customer::where('id', '=', $id)->first();
     //$data['customerhistory'] = $customerlog->get()->toArray();
     $data['customerhistory'] = groupThem($customerlog->get()->toArray(), 'receipt_id');
     $data['customerdetail'] = $customerDetails;
     $data['fromdate'] = $from;
     $this->layout->title = 'Customer History';
     $this->layout->content = View::make('admin.customerhistory', $data);
 }
Ejemplo n.º 4
0
 private function keepSalesLog($data, $customer_id)
 {
     $others = $data['others'];
     unset($data['others']);
     //tt($others);
     foreach ($data as $index => $array) {
         foreach ($array as $id => $dataArray) {
             $sale = new Salelog();
             $sale->product_id = $id;
             $sale->receipt_id = $this->receiptID;
             $sale->mode_id = $this->modeID($dataArray['salesmodename']);
             $sale->user_id = Auth::user()->id;
             $sale->customer_id = $customer_id;
             //$sale->saletime = strtotime('now');
             unset($dataArray['salesmodename']);
             // Unset salemodename before db logging
             unset($dataArray['cat_type']);
             // Unset cat_type before db logging
             foreach ($dataArray as $field => $value) {
                 $sale->{$field} = $value;
                 //tt($field . '=>' . $value, true);
             }
             $sale->save();
         }
     }
 }