Ejemplo n.º 1
0
 public function actionInvoice($id)
 {
     if (Yii::$app->user->identity->type == 'normal') {
         return $this->redirect(['update', 'id' => $id]);
     }
     $admin_id = Yii::$app->user->identity->id;
     $model = $this->findModel($id);
     $invoice = Invoice::find();
     $invoice = $invoice->where('job_id=' . $id);
     $invoice = $invoice->orderBy('id DESC');
     $invoice = $invoice->asArray();
     $invoice = $invoice->limit(1);
     $invoice = $invoice->all();
     // $companies = Company::find();
     // if(Yii::$app->user->identity->type=='normal'){
     //     $companies = $companies->innerJoin('wolf_admin_to_company wc','wc.company_id=wolf_company.company_id');
     //     $companies = $companies->where('admin_id='.$admin_id);
     // }
     // $companies = $companies->orderBy('company_name');
     // $companies = $companies->asArray();
     // $companies = $companies->all();
     $jobScheduleSearch = new JobScheduleSearch(['job_id' => $id]);
     $scheduleData = $jobScheduleSearch->search(Yii::$app->request->getQueryParams());
     $scheduleData->pagination->pageSize = -1;
     //infinite value
     return $this->render('invoice', ['model' => $this->findModel($id), 'scheduleData' => $scheduleData, 'jobScheduleSearch' => $jobScheduleSearch, 'invoice' => $invoice]);
 }
 public function update($id, Request $request)
 {
     $invoice = Invoice::find($id);
     $rules = $invoice->getValidatorRules();
     $validator = $this->validate($request, $rules);
     if ($validator) {
         return response()->json($validator, '404');
     }
     $input = $request->all();
     $invoice->update($input);
     /**
     |-----------------------------------------------------
     | Add customer to invoice
     |-----------------------------------------------------
     */
     $customer_id = $request->get('customer')['id'];
     $customer = Customer::find($customer_id);
     $invoice->updateCustomerWithShippingAddress($customer);
     /**
     |-----------------------------------------------------
     | Add list products to invoice
     |-----------------------------------------------------
     */
     $invoice->addProductItems($request->get('items'));
     /**
     |-----------------------------------------------------
     | Save to Db
     |-----------------------------------------------------
     */
     redirect()->route('sale.invoice.show', [$invoice], 302);
 }
Ejemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Invoice::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'zip' => $this->zip]);
     $query->andFilterWhere(['like', 'business_name', $this->business_name])->andFilterWhere(['like', 'rfc', $this->rfc])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'state', $this->state])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
Ejemplo n.º 4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Invoice::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'job_id' => $this->job_id, 'company_id' => $this->company_id, 'invoice_date' => $this->invoice_date]);
     $query->andFilterWhere(['like', 'invoice_no', $this->invoice_no]);
     return $dataProvider;
 }
Ejemplo n.º 5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = InvoiceModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'amount' => $this->amount]);
     if (isset($params['user'])) {
         $query->andFilterWhere(['user_name' => $params['user']]);
     }
     $query->andFilterWhere(['like', 'user_name', $this->user_name])->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     try {
         $admin = \Auth::User();
         if (!$admin) {
             return $this->failResponse('admin not logged in');
         }
         $invoiceObj = Invoice::find($id);
         if (count($invoiceObj) == 0) {
             return $this->failResponse('customer id not found');
         }
         $invoiceObj->delete();
         return $this->successResponse('customer deleted successfully');
     } catch (\Exception $e) {
         Log::error("error in customer controller");
         return $this->failResponse($e->getMessage());
     }
 }