/** * @test */ public function get_current_cost_for_material() { $material = Material::find(13); $this->assertInstanceOf(Material::class, $material); $cost_logs_last = $material->costLogs->sortByDesc('mat_cost_date')->first()->mat_cost_cost_kg; $cost = $material->current_cost->mat_cost_cost_kg; $this->assertEquals($cost_logs_last, $cost, "Current Cost"); }
public function index() { // $discardedMaterials = Material::where('type', array_flip(Config::get('common.material_type'))['Discarded'])->lists('id'); // $discardedMaterialStocks = RawStock::whereIn('id', $discardedMaterials)->paginate(Config::get('common.pagination')); // // $materials = Material::lists('name', 'id'); // return view('discardedStock.index', compact('discardedMaterialStocks', 'materials')); $materials = Material::where('type', array_flip(Config::get('common.material_type'))['Discarded'])->lists('name', 'id'); return view('discardedStock.create', compact('materials')); }
/** * Bootstrap the application services. */ public function boot() { User::observe('App\\Observers\\UserObserver'); Reply::observe('App\\Observers\\ReplyObserver'); Event::observe('App\\Observers\\EventObserver'); Material::observe('App\\Observers\\MaterialObserver'); Account::observe('App\\Observers\\AccountObserver'); FanGroup::observe('App\\Observers\\FanGroupObserver'); Fan::observe('App\\Observers\\FanObserver'); }
/** * Overwrite the parent boot method * * @return void */ public static function boot() { parent::boot(); Material::creating(function ($material) { $material->material_added_user_id_fk = \Auth::user()->id; $material->material_modified_user_id_fk = \Auth::user()->id; }); Material::updating(function ($material) { $material->material_modified_user_id_fk = \Auth::user()->id; }); }
/** * Overwrite the parent boot method * * @return void */ public static function boot() { parent::boot(); Ink::creating(function ($ink) { $ink->ink_added_user_id_fk = \Auth::user()->id; $ink->ink_modified_user_id_fk = \Auth::user()->id; }); Material::updating(function ($ink) { $ink->ink_modified_user_id_fk = \Auth::user()->id; }); }
public function update($id, MaterialRequest $request) { $material = Material::findOrFail($id); $material->name = $request->input('name'); $material->type = $request->input('type'); $material->status = $request->input('status'); $material->updated_by = Auth::user()->id; $material->updated_at = time(); $material->update(); Session()->flash('flash_message', 'Material has been updated!'); return redirect('materials'); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Material::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $materialConfig = array_flip(Config::get('common.material_type')); $suppliers = Supplier::where('status', 1)->lists('company_name', 'id'); $rmaterials = Material::where('status', 1)->where('type', '!=', $materialConfig['Discarded'])->select('name', 'id', 'type')->get(); $materials = []; foreach ($rmaterials as $material) { if ($material->type != 1) { $materials[$material->id] = Config::get('common.material_type')[$material->type] . ' - ' . $material->name; } else { $materials[$material->id] = $material->name; } } $raw_stock = RawStock::lists('quantity', 'material_id'); return view('purchasesReturn.create', compact('suppliers', 'materials', 'raw_stock')); }
/** * @test */ public function material_edit_complete_form_submit_correct() { $this->visit('/material/13/edit')->see('MTech MIS Login Screen'); $user = User::find(46); $this->actingAs($user)->visit('/material/13/edit')->type("cOPP20", 'material_description')->type("Clear BOPP20", 'material_fronthouse_name')->type("20", 'material_micron')->select("8", 'material_supplier_id_fk')->select("7", 'material_grade_id_fk')->select("KG", 'material_uom')->type("14", 'material_lead_time')->select("1", 'material_buy')->type("Test notes", 'material_notes')->press("Save")->assertSessionHas('flash'); $this->assertResponseOk(); $material = Material::find(13); $this->assertEquals('cOPP20', $material->material_description); $this->assertEquals('Clear BOPP20', $material->material_fronthouse_name); $this->assertEquals('20', $material->material_micron); $this->assertEquals('8', $material->material_supplier_id_fk); $this->assertEquals('7', $material->material_grade_id_fk); $this->assertEquals('KG', $material->material_uom); $this->assertEquals('14', $material->material_lead_time); $this->assertEquals('1', $material->material_buy); $this->assertEquals('Test notes', $material->material_notes); }
/** * Create / add new item to material inventory * * @param Requests\AddMaterialInventoryPostRequest $request * @return $this * @internal param JobCard $job_card */ public function create() { $this->authorize('edit_material_inventory'); return view('warehouse.material_inventory.create')->with(['material_grades' => Material::all(), 'material_inventory' => MaterialInventoryItem::orderBy('material_inventory_id', 'desc')->limit(50)->get()]); }
public function acceptanceStore(Request $req) { $vals = ['po_id' => $_POST['po_id'], 'pener_date' => now(), 'userid_input' => Auth::user()->user_id, 'visibility' => 1]; $pener = Pener::create($vals); foreach ($_POST['pos_id'] as $pos_id) { if (!empty($_POST['peners_jml_' . $pos_id])) { $vals = ['pener_id' => $pener->pener_id, 'pos_id' => $pos_id, 'peners_jml' => $_POST['peners_jml_' . $pos_id]]; Peners::create($vals); if (!empty($_POST['mat_id_' . $pos_id])) { $mat = MatModel::find($_POST['mat_id_' . $pos_id]); $mat->mat_stock_akhir = $mat->mat_stock_akhir + $_POST['peners_jml_' . $pos_id]; $mat->save(); } } } #Checking for update po_status $sub = Po_sub::fetchDetail($_POST['po_id']); $el = array(); foreach ($sub as $row) { $diterima = countDiterima($row->pos_id); $rest = $row->pbs_jml - $diterima; if ($rest > 0) { array_push($el, 'open'); } } if (!in_array('open', $el)) { $rec = Po::find($_POST['po_id']); $rec->po_status = 2; $rec->save(); } #End of checking Session::flash('inserted', '<div class="info success">Penerimaan material berhasil diinput.</div>'); return redirect('material/acceptance'); }
public function edit($id) { $UsageRegister = UsageRegister::findOrFail($id); $materialConfig = array_flip(Config::get('common.material_type')); $rawMaterials = Material::where('status', 1)->where('type', '!=', $materialConfig['Discarded'])->select('name', 'id', 'type')->get(); $materials = []; foreach ($rawMaterials as $material) { if ($material->type != 1) { $materials[$material->id] = Config::get('common.material_type')[$material->type] . ' - ' . $material->name; } else { $materials[$material->id] = $material->name; } } return view('usageRegisters.edit', compact('UsageRegister', 'materials')); }
/** * Search in materials. * * @param string $search * @return Response */ public function search($id, $search) { $courses = Material::where('description', 'like', '%' . $search . '%')->where('subject_id', $id)->take(6)->get(); $return = []; foreach ($courses as $key => $course) { if ($course->filtered) { $return[] = ['id' => $course->id, 'description' => $course->description, 'link_url' => $course->link_url, 'tag' => $course->tag->name]; } } return response()->json($return); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $product = Product::findOrFail($id); $product_types = ProductType::lists('title', 'id'); $color = Material::where('type', 3)->lists('name', 'id'); return view('products.edit', compact('product', 'product_types', 'color')); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $suppliers = Supplier::where('status', 1)->lists('company_name', 'id'); $materials = Material::where('status', 1)->lists('name', 'id'); $purchase = Purchase::with('purchaseDetails')->findOrFail($id); return view('purchases.edit', compact('suppliers', 'materials', 'purchase')); }
public function edit($id) { $customers = Customer::where('status', 1)->lists('name', 'id'); $suppliers = Supplier::where('status', 1)->lists('company_name', 'id'); $employees = Supplier::where('status', 1)->lists('name', 'id'); $providers = Supplier::where('status', 1)->lists('name', 'id'); $materials = Material::where('type', array_flip(Config::get('common.material_type'))['Discarded'])->lists('name', 'id'); $discardedSales = DiscardedSales::with(['DiscardedSalesDetail' => function ($q) { $q->where('status', 1); }])->findOrFail($id); return view('discardedSales.edit', compact('discardedSales', 'customers', 'materials', 'suppliers', 'employees', 'providers')); }
/** * Finds the Material model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Material the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Material::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function edit($id) { $types = Config::get('common.material_type'); $material = Material::findOrFail($id); return view('materialStockInitializations.edit', compact('types', 'material')); }
/** * @return \yii\db\ActiveQuery */ public function getMaterial() { return $this->hasOne(Material::className(), ['id' => 'material_id']); }
/** * update. * * @param int $id * @param array $input */ public function update($id, $input) { $model = $this->model->find($id); return $this->fillSavePost($model, $input); }
public function closingStockDo(Request $req) { $cs = Cs::create(['user_id' => $this->_user->user_id, 'cs_year' => $req->input('year')]); foreach (MatModel::fetchForClosing() as $row) { $vals = ['cs_id' => $cs->cs_id, 'mat_id' => $row->mat_id, 'mat_stock_awal' => $row->mat_stock_awal, 'mat_stock_akhir' => $row->mat_stock_akhir]; Csm::create($vals); $mat = MatModel::find($row->mat_id); $mat->mat_stock_awal = $mat->mat_stock_akhir; $mat->save(); } Session::flash('success', '<div class="info success">Closing Stok untuk tahun ' . $req->input('year') . ' berhasil dilakukan.</div>'); return redirect('material/closingStock'); }
public function expenditure(Request $req) { $dEnd = $req->input('year') . '-' . $req->input('month'); $data = ['title' => 'Laporan Pengeluaran Bulanan Material', 'asset' => new Assets(), 'period' => libMonths()[$req->input('month')] . ' ' . $req->input('year'), 'dStart' => date('Y-m', strtotime('-5 months', strtotime($dEnd))), 'dEnd' => $dEnd, 'fetch' => Material::fetchForReport(), 'Pengels' => new Pengels()]; return view('printing.expenditure', $data); }
public function update($id, Request $request) { $this->validate($request, ['product' => 'array', 'total' => 'required']); // dd($request->input()); try { DB::transaction(function () use($id, $request) { $inputs = $request->input(); $user = Auth::user(); $time = time(); $date = strtotime(date('d-m-Y')); $year = CommonHelper::get_current_financial_year(); $transaction_type = Config::get('common.transaction_type.defect_receive'); $balance_type = Config::get('common.balance_type_intermediate'); //Defect table affected. $defect = Defect::find($id); $oldDefect = clone $defect; $defect->total = $inputs['total']; $defect->cash = $inputs['cash']; $defect->due_paid = $inputs['due_paid']; $defect->due = $inputs['due']; if (isset($inputs['is_replacement'])) { $defect->is_replacement = $inputs['is_replacement']; $defect->replacement = $inputs['new_total']; } $defect->remarks = $inputs['remarks']; $defect->updated_by = $user->id; $defect->updated_at = $time; $defect->update(); $defect_amount = $inputs['cash'] + $inputs['due_paid'] + $inputs['due']; if ($defect_amount > 0) { $journal = GeneralJournal::where('account_code', '=', 36000)->where('workspace_id', '=', $user->workspace_id)->where('reference_id', '=', $id)->where('transaction_type', '=', $transaction_type)->where('year', '=', $year)->first(); $journal->amount = $defect_amount; $journal->updated_by = $user->id; $journal->updated_at = $time; $journal->update(); $workspace = WorkspaceLedger::where(['account_code' => 36000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); if ($oldDefect->total > $defect_amount) { $workspace->balance += $oldDefect->total - $defect_amount; //sub defect receive } elseif ($oldDefect->total < $defect_amount) { $workspace->balance += $defect_amount - $oldDefect->total; //sub defect receive } $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); } else { $journal = GeneralJournal::where('account_code', '=', 36000)->where('workspace_id', '=', $user->workspace_id)->where('reference_id', '=', $id)->where('transaction_type', '=', $transaction_type)->where('year', '=', $year)->first(); $journal->delete(); $workspace = WorkspaceLedger::where(['account_code' => 36000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance -= $oldDefect->cash + $oldDefect->due_paid + $oldDefect->due; //sub defect receive $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); } if (isset($inputs['delete_product'])) { foreach ($inputs['delete_product'] as $product) { $defectItem = DefectItem::where('defect_id', '=', $id)->where('product_id', '=', $product['product_id'])->first(); if ($defectItem) { $defectItem->delete(); } } } //Get Scrap Id $material = Material::where('name', '=', 'Scrap')->where('status', '=', 1)->first(); //Old Defect Items foreach ($inputs['old_product'] as $product) { $defectItem = DefectItem::where('defect_id', '=', $id)->where('product_id', '=', $product['product_id'])->first(); $oldDefectItem = clone $defectItem; $defectItem->quantity = $product['receive_quantity']; $defectItem->unit_type = $product['unit_type']; $defectItem->unit_price = $product['unit_price']; $defectItem->updated_by = $user->id; $defectItem->updated_at = $time; $defectItem->update(); //Material stock updated $rawStock = RawStock::where('year', '=', $year)->where('stock_type', '=', Config::get('common.balance_type_intermediate'))->where('material_id', '=', $material->id)->first(); if ($product['unit_type'] == 1) { if ($oldDefectItem->unit_type == 1) { if ($oldDefectItem->quantity > $product['receive_quantity']) { $rawStock->quantity -= ($oldDefectItem->quantity - $product['receive_quantity']) / $product['length'] * $product['weight']; } elseif ($oldDefectItem->quantity < $product['receive_quantity']) { $rawStock->quantity += ($product['receive_quantity'] - $oldDefectItem->quantity) / $product['length'] * $product['weight']; } } elseif ($oldDefectItem->unit_type == 2) { $old_quantity = $oldDefectItem->quantity / $product['weight'] * $product['length']; if ($old_quantity > $product['receive_quantity']) { $rawStock->quantity -= ($old_quantity - $product['receive_quantity']) / $product['length'] * $product['weight']; } elseif ($old_quantity < $product['receive_quantity']) { $rawStock->quantity += ($product['receive_quantity'] - $old_quantity) / $product['length'] * $product['weight']; } } } elseif ($product['unit_type'] == 2) { if ($oldDefectItem->unit_type == 1) { $old_quantity = $oldDefectItem->quantity / $product['length'] * $product['weight']; if ($old_quantity > $product['receive_quantity']) { $rawStock->quantity -= $old_quantity - $product['receive_quantity']; } elseif ($old_quantity < $product['receive_quantity']) { $rawStock->quantity += $product['receive_quantity'] - $old_quantity; } } elseif ($oldDefectItem->unit_type == 2) { if ($oldDefectItem->quantity > $product['receive_quantity']) { $rawStock->quantity -= $oldDefectItem->quantity - $product['receive_quantity']; } elseif ($oldDefectItem->quantity < $product['receive_quantity']) { $rawStock->quantity += $product['receive_quantity'] - $oldDefectItem->quantity; } } } $rawStock->updated_by = $user->id; $rawStock->updated_at = $time; $rawStock->update(); } //New Defect Items if (!empty($inputs['product'])) { foreach ($inputs['product'] as $product) { $defectItem = new DefectItem(); $defectItem->defect_id = $id; $defectItem->product_id = $product['product_id']; $defectItem->quantity = $product['receive_quantity']; $defectItem->unit_type = $product['unit_type']; $defectItem->unit_price = $product['unit_price']; $defectItem->created_by = $user->id; $defectItem->created_at = $time; $defectItem->save(); //Material stock updated $rawStock = RawStock::where('year', '=', $year)->where('stock_type', '=', Config::get('common.balance_type_intermediate'))->where('material_id', '=', $material->id)->first(); if ($product['unit_type'] == 1) { $rawStock->quantity += $product['receive_quantity'] / $product['length'] * $product['weight']; } else { $rawStock->quantity += $product['receive_quantity']; } $rawStock->updated_by = $user->id; $rawStock->updated_at = $time; $rawStock->update(); } } if ($inputs['cash'] && !$oldDefect->cash) { //Cash $journal = new GeneralJournal(); $journal->date = $date; $journal->transaction_type = $transaction_type; $journal->reference_id = $id; $journal->year = $year; $journal->account_code = 11000; //Cash $journal->dr_cr_indicator = Config::get('common.debit_credit_indicator.credit'); $journal->workspace_id = $user->workspace_id; $journal->amount = $inputs['cash']; $journal->created_by = $user->id; $journal->created_at = $time; $journal->save(); $workspace = WorkspaceLedger::where(['account_code' => 11000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance -= $inputs['cash'] - $oldDefect->cash; //sub cash $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); } elseif (!$inputs['cash'] && $oldDefect->cash) { //Cash $journal = GeneralJournal::where('account_code', '=', 11000)->where('workspace_id', '=', $user->workspace_id)->where('reference_id', '=', $id)->where('transaction_type', '=', $transaction_type)->where('year', '=', $year)->first(); $journal->delete(); $workspace = WorkspaceLedger::where(['account_code' => 11000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance += $oldDefect->cash; //add cash $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); } elseif ($inputs['cash'] > $oldDefect->cash) { $workspace = WorkspaceLedger::where(['account_code' => 11000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); if ($workspace->balance < $inputs['cash'] - $oldDefect->cash) { Session()->flash('warning_message', 'Insufficient cash balance!.'); throw new \Exception(); } $workspace->balance -= $inputs['cash'] - $oldDefect->cash; //sub cash $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); $journal = GeneralJournal::where('account_code', '=', 11000)->where('workspace_id', '=', $user->workspace_id)->where('reference_id', '=', $id)->where('transaction_type', '=', $transaction_type)->where('year', '=', $year)->first(); $journal->amount = $inputs['cash']; $journal->updated_by = $user->id; $journal->updated_at = $time; $journal->update(); } elseif ($inputs['cash'] < $oldDefect->cash) { $journal = GeneralJournal::where('account_code', '=', 11000)->where('workspace_id', '=', $user->workspace_id)->where('reference_id', '=', $id)->where('transaction_type', '=', $transaction_type)->where('year', '=', $year)->first(); $journal->amount = $inputs['cash']; $journal->updated_by = $user->id; $journal->updated_at = $time; $journal->update(); $workspace = WorkspaceLedger::where(['account_code' => 11000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance += $oldDefect->cash - $inputs['cash']; //add cash $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); } if ($inputs['due_paid'] && !$oldDefect->due_paid) { //Due Pay $journal = new GeneralJournal(); $journal->date = $date; $journal->transaction_type = $transaction_type; $journal->reference_id = $defect->id; $journal->year = $year; $journal->account_code = 12000; //Account Receivable $journal->dr_cr_indicator = Config::get('common.debit_credit_indicator.credit'); $journal->workspace_id = $user->workspace_id; $journal->amount = $inputs['due_paid']; $journal->created_by = $user->id; $journal->created_at = $time; $journal->save(); $workspace = WorkspaceLedger::where(['account_code' => 12000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance -= $inputs['due_paid']; //sub account receivable $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); $personalAccount = PersonalAccount::where('person_type', '=', $oldDefect->customer_type)->where('person_id', '=', $inputs['customer_id'])->first(); $personalAccount->due -= $inputs['due_paid']; //Sub due $personalAccount->updated_by = $user->id; $personalAccount->updated_at = $time; $personalAccount->update(); } elseif (!$inputs['due_paid'] && $oldDefect->due_paid) { $journal = GeneralJournal::where('account_code', '=', 12000)->where('workspace_id', '=', $user->workspace_id)->where('reference_id', '=', $id)->where('transaction_type', '=', $transaction_type)->where('year', '=', $year)->first(); $journal->delete(); $workspace = WorkspaceLedger::where(['account_code' => 12000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance += $oldDefect->due_paid; //add account receivable $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); $personalAccount = PersonalAccount::where('person_type', '=', $oldDefect->customer_type)->where('person_id', '=', $inputs['customer_id'])->first(); $personalAccount->due += $oldDefect->due_paid; //add due $personalAccount->updated_by = $user->id; $personalAccount->updated_at = $time; $personalAccount->update(); } elseif ($inputs['due_paid'] > $oldDefect->due_paid) { $journal = GeneralJournal::where('account_code', '=', 12000)->where('workspace_id', '=', $user->workspace_id)->where('reference_id', '=', $id)->where('transaction_type', '=', $transaction_type)->where('year', '=', $year)->first(); $journal->amount = $inputs['due_paid']; $journal->updated_by = $user->id; $journal->updated_at = $time; $journal->update(); $workspace = WorkspaceLedger::where(['account_code' => 12000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance -= $inputs['due_paid'] - $oldDefect->due_paid; //sub account receivable $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); $personalAccount = PersonalAccount::where('person_type', '=', $oldDefect->customer_type)->where('person_id', '=', $inputs['customer_id'])->first(); $personalAccount->due -= $inputs['due_paid'] - $oldDefect->due_paid; //Sub due $personalAccount->updated_by = $user->id; $personalAccount->updated_at = $time; $personalAccount->update(); } elseif ($inputs['due_paid'] < $oldDefect->due_paid) { $journal = GeneralJournal::where('account_code', '=', 12000)->where('workspace_id', '=', $user->workspace_id)->where('reference_id', '=', $id)->where('transaction_type', '=', $transaction_type)->where('year', '=', $year)->first(); $journal->amount = $inputs['due_paid']; $journal->updated_by = $user->id; $journal->updated_at = $time; $journal->update(); $workspace = WorkspaceLedger::where(['account_code' => 12000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance += $oldDefect->due_paid - $inputs['due_paid']; //add account receivable $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); $personalAccount = PersonalAccount::where('person_type', '=', $oldDefect->customer_type)->where('person_id', '=', $oldDefect->customer_id)->first(); $personalAccount->due += $oldDefect->due_paid - $inputs['due_paid']; //add due $personalAccount->updated_by = $user->id; $personalAccount->updated_at = $time; $personalAccount->update(); } if ($inputs['due'] && !$oldDefect->due) { // Due $journal = new GeneralJournal(); $journal->date = $date; $journal->transaction_type = $transaction_type; $journal->reference_id = $defect->id; $journal->year = $year; $journal->account_code = 41000; //Account Payable $journal->dr_cr_indicator = Config::get('common.debit_credit_indicator.credit'); $journal->workspace_id = $user->workspace_id; $journal->amount = $inputs['due']; $journal->created_by = $user->id; $journal->created_at = $time; $journal->save(); $workspace = WorkspaceLedger::where(['account_code' => 41000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance += $inputs['due']; //add account payable $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); $personalAccount = PersonalAccount::where('person_type', '=', $oldDefect->customer_type)->where('person_id', '=', $inputs['customer_id'])->first(); $personalAccount->balance += $inputs['due']; //Add Balance $personalAccount->updated_by = $user->id; $personalAccount->updated_at = $time; $personalAccount->update(); } elseif (!$inputs['due'] && $oldDefect->due) { // Due $journal = GeneralJournal::where('account_code', '=', 41000)->where('workspace_id', '=', $user->workspace_id)->where('reference_id', '=', $id)->where('transaction_type', '=', $transaction_type)->where('year', '=', $year)->first(); $journal->delete(); $workspace = WorkspaceLedger::where(['account_code' => 41000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance -= $oldDefect->due; //sub account payable $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); $personalAccount = PersonalAccount::where('person_type', '=', $oldDefect->customer_type)->where('person_id', '=', $inputs['customer_id'])->first(); $personalAccount->balance -= $oldDefect->due; //Sub Balance $personalAccount->updated_by = $user->id; $personalAccount->updated_at = $time; $personalAccount->update(); } elseif ($inputs['due'] > $oldDefect->due) { // Due $journal = GeneralJournal::where('account_code', '=', 41000)->where('workspace_id', '=', $user->workspace_id)->where('reference_id', '=', $id)->where('transaction_type', '=', $transaction_type)->where('year', '=', $year)->first(); $journal->amount = $inputs['due']; $journal->updated_by = $user->id; $journal->updated_at = $time; $journal->update(); $workspace = WorkspaceLedger::where(['account_code' => 41000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance += $inputs['due'] - $oldDefect->due; //add account payable $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); $personalAccount = PersonalAccount::where('person_type', '=', $oldDefect->customer_type)->where('person_id', '=', $inputs['customer_id'])->first(); $personalAccount->balance += $inputs['due'] - $oldDefect->due; //Add Balance $personalAccount->updated_by = $user->id; $personalAccount->updated_at = $time; $personalAccount->update(); } elseif ($inputs['due'] < $oldDefect->due) { // Due $journal = GeneralJournal::where('account_code', '=', 41000)->where('workspace_id', '=', $user->workspace_id)->where('reference_id', '=', $id)->where('transaction_type', '=', $transaction_type)->where('year', '=', $year)->first(); $journal->amount = $inputs['due']; $journal->updated_by = $user->id; $journal->updated_at = $time; $journal->update(); $workspace = WorkspaceLedger::where(['account_code' => 41000, 'workspace_id' => $user->workspace_id, 'balance_type' => $balance_type, 'year' => $year])->first(); $workspace->balance -= $oldDefect->due - $inputs['due']; //sub account payable $workspace->updated_by = $user->id; $workspace->updated_at = $time; $workspace->update(); $personalAccount = PersonalAccount::where('person_type', '=', $oldDefect->customer_type)->where('person_id', '=', $inputs['customer_id'])->first(); $personalAccount->balance -= $oldDefect->due - $inputs['due']; //sub Balance $personalAccount->updated_by = $user->id; $personalAccount->updated_at = $time; $personalAccount->update(); } if (isset($inputs['is_replacement']) && !$oldDefect->is_replacement) { //Replacement $defectReplacement = new SalesOrder(); $defectReplacement->workspace_id = $user->workspace_id; $defectReplacement->defect_id = $defect->id; $defectReplacement->order_type = Config::get('common.sales_order_type.replacement'); $defectReplacement->customer_id = $inputs['customer_id']; $defectReplacement->customer_type = $oldDefect->customer_type; $defectReplacement->total = $inputs['new_total']; $defectReplacement->date = $time; $defectReplacement->delivery_status = 1; $defectReplacement->created_by = $user->id; $defectReplacement->created_at = $time; $defectReplacement->save(); foreach ($inputs['new_product'] as $new_product) { $defectReplacementItem = new SalesOrderItem(); $defectReplacementItem->sales_order_id = $defectReplacement->id; $defectReplacementItem->product_id = $new_product['product_id']; $defectReplacementItem->sales_quantity = $new_product['sales_quantity']; $defectReplacementItem->sales_unit_type = $new_product['sales_unit_type']; $defectReplacementItem->unit_price = $new_product['unit_price']; $defectReplacementItem->created_by = $user->id; $defectReplacementItem->created_at = $time; $defectReplacementItem->save(); $stock = Stock::where('product_id', '=', $new_product['product_id'])->where('stock_type', '=', $balance_type)->where('year', '=', $year)->first(); if ($new_product['sales_unit_type'] == 1) { if ($stock->quantity < $new_product['sales_quantity']) { Session()->flash('warning_message', 'Insufficient stock!.'); throw new \Exception(); } $stock->quantity -= $new_product['sales_quantity']; //Sub stock } elseif ($new_product['sales_unit_type'] == 2) { $sales_quantity = $new_product['sales_quantity'] / $new_product['weight'] * $new_product['length']; if ($stock->quantity < $sales_quantity) { Session()->flash('warning_message', 'Insufficient stock!.'); throw new \Exception(); } $stock->quantity -= $sales_quantity; //Sub stock } $stock->updated_by = $user->id; $stock->updated_at = $time; $stock->update(); } } elseif (isset($inputs['is_replacement']) && $oldDefect->is_replacement) { $defectReplacement = SalesOrder::where('defect_id', '=', $id)->first(); $oldDefectReplacement = clone $defectReplacement; $defectReplacement->total = $inputs['new_total']; $defectReplacement->updated_by = $user->id; $defectReplacement->updated_at = $time; $defectReplacement->update(); if (isset($inputs['delete_replacement_product'])) { foreach ($inputs['delete_replacement_product'] as $product) { $defectReplacementItem = SalesOrderItem::where('sales_order_id', '=', $defectReplacement->id)->where('product_id', '=', $product['product_id'])->first(); if ($defectReplacementItem) { $defectReplacementItem->delete(); } } } //Old Product foreach ($inputs['old_replacement_product'] as $new_product) { $defectReplacementItem = SalesOrderItem::where('sales_order_id', '=', $defectReplacement->id)->where('product_id', '=', $new_product['product_id'])->first(); $oldDefectReplacementItem = clone $defectReplacementItem; $defectReplacementItem->sales_quantity = $new_product['sales_quantity']; $defectReplacementItem->sales_unit_type = $new_product['sales_unit_type']; $defectReplacementItem->unit_price = $new_product['unit_price']; $defectReplacementItem->updated_by = $user->id; $defectReplacementItem->updated_at = $time; $defectReplacementItem->update(); $stock = Stock::where('product_id', '=', $new_product['product_id'])->where('stock_type', '=', $balance_type)->where('year', '=', $year)->first(); if ($oldDefectReplacementItem->sales_unit_type == 1) { if ($new_product['sales_unit_type'] == 1) { if ($oldDefectReplacementItem->sales_quantity > $new_product['sales_quantity']) { $stock->quantity += $oldDefectReplacementItem->sales_quantity - $new_product['sales_quantity']; //Add stock } elseif ($oldDefectReplacementItem->sales_quantity < $new_product['sales_quantity']) { $sales_quantity = $new_product['sales_quantity'] - $oldDefectReplacementItem->sales_quantity; if ($stock->quantity < $sales_quantity) { Session()->flash('warning_message', 'Insufficient stock!.'); throw new \Exception(); } $stock->quantity -= $sales_quantity; //Sub stock } } elseif ($new_product['sales_unit_type'] == 2) { $new_sales_quantity = $new_product['sales_quantity'] / $new_product['weight'] * $new_product['length']; if ($oldDefectReplacementItem->sales_quantity > $new_sales_quantity) { $stock->quantity += $oldDefectReplacementItem->sales_quantity - $new_sales_quantity; //Add stock } elseif ($oldDefectReplacementItem->sales_quantity < $new_sales_quantity) { $sales_quantity = $new_sales_quantity - $oldDefectReplacementItem->sales_quantity; if ($stock->quantity < $sales_quantity) { Session()->flash('warning_message', 'Insufficient stock!.'); throw new \Exception(); } $stock->quantity -= $sales_quantity; //Sub stock } } } elseif ($oldDefectReplacementItem->sales_unit_type == 2) { if ($new_product['sales_unit_type'] == 1) { $new_sales_quantity = $oldDefectReplacementItem->sales_quantity / $new_product['weight'] * $new_product['length']; if ($new_sales_quantity > $new_product['sales_quantity']) { $stock->quantity += $new_sales_quantity - $new_product['sales_quantity']; $stock->quantity += $new_sales_quantity - $new_product['sales_quantity']; //Add stock } elseif ($new_sales_quantity < $new_product['sales_quantity']) { $sales_quantity = $new_product['sales_quantity'] - $new_sales_quantity; //Sub stock if ($stock->quantity < $sales_quantity) { Session()->flash('warning_message', 'Insufficient stock!.'); throw new \Exception(); } $stock->quantity -= $sales_quantity; //Sub stock } } elseif ($new_product['sales_unit_type'] == 2) { $old_sales_quantity = $oldDefectReplacementItem->sales_quantity / $new_product['weight'] * $new_product['length']; $new_sales_quantity = $new_product['sales_quantity'] / $new_product['weight'] * $new_product['length']; if ($old_sales_quantity > $new_sales_quantity) { $stock->quantity += $old_sales_quantity - $new_sales_quantity; //Add stock } elseif ($old_sales_quantity < $new_sales_quantity) { $sales_quantity = $new_sales_quantity - $old_sales_quantity; if ($stock->quantity < $sales_quantity) { Session()->flash('warning_message', 'Insufficient stock!.'); throw new \Exception(); } $stock->quantity -= $sales_quantity; //Sub stock } } } $stock->updated_by = $user->id; $stock->updated_at = $time; $stock->update(); } //New Product if (!empty($inputs['new_product'])) { foreach ($inputs['new_product'] as $new_product) { $defectReplacementItem = new SalesOrderItem(); $defectReplacementItem->sales_order_id = $defectReplacement->id; $defectReplacementItem->product_id = $new_product['product_id']; $defectReplacementItem->sales_quantity = $new_product['sales_quantity']; $defectReplacementItem->sales_unit_type = $new_product['sales_unit_type']; $defectReplacementItem->unit_price = $new_product['unit_price']; $defectReplacementItem->created_by = $user->id; $defectReplacementItem->created_at = $time; $defectReplacementItem->save(); $stock = Stock::where('product_id', '=', $new_product['product_id'])->where('stock_type', '=', $balance_type)->where('year', '=', $year)->first(); $stock->quantity -= $new_product['sales_quantity']; //Sub stock $stock->updated_by = $user->id; $stock->updated_at = $time; $stock->update(); } } } elseif (!isset($inputs['is_replacement']) && $oldDefect->is_replacement) { $defectReplacement = SalesOrder::where('defect_id', '=', $id)->first(); $oldDefectReplacement = clone $defectReplacement; $defectReplacement->total = $inputs['new_total']; $defectReplacement->updated_by = $user->id; $defectReplacement->updated_at = $time; $defectReplacement->update(); if (isset($inputs['delete_replacement_product'])) { foreach ($inputs['delete_replacement_product'] as $product) { $defectReplacementItem = SalesOrderItem::where('sales_order_id', '=', $defectReplacement->id)->where('product_id', '=', $product['product_id'])->first(); if ($defectReplacementItem) { $defectReplacementItem->delete(); } } } //Old Product foreach ($inputs['old_replacement_product'] as $new_product) { $defectReplacementItem = SalesOrderItem::where('sales_order_id', '=', $defectReplacement->id)->where('product_id', '=', $new_product['product_id'])->first(); $oldDefectReplacementItem = clone $defectReplacementItem; $defectReplacementItem->sales_quantity = $new_product['sales_quantity']; $defectReplacementItem->sales_unit_type = $new_product['sales_unit_type']; $defectReplacementItem->unit_price = $new_product['unit_price']; $defectReplacementItem->updated_by = $user->id; $defectReplacementItem->updated_at = $time; $defectReplacementItem->update(); $stock = Stock::where('product_id', '=', $new_product['product_id'])->where('stock_type', '=', $balance_type)->where('year', '=', $year)->first(); if ($oldDefectReplacementItem->sales_unit_type == 1) { if ($new_product['sales_unit_type'] == 1) { if ($oldDefectReplacementItem->sales_quantity > $new_product['sales_quantity']) { $stock->quantity += $oldDefectReplacementItem->sales_quantity - $new_product['sales_quantity']; //Add stock } elseif ($oldDefectReplacementItem->sales_quantity < $new_product['sales_quantity']) { $sales_quantity = $new_product['sales_quantity'] - $oldDefectReplacementItem->sales_quantity; if ($stock->quantity < $sales_quantity) { Session()->flash('warning_message', 'Insufficient stock!.'); throw new \Exception(); } $stock->quantity -= $sales_quantity; //Sub stock } } elseif ($new_product['sales_unit_type'] == 2) { $new_sales_quantity = $new_product['sales_quantity'] / $new_product['weight'] * $new_product['length']; if ($oldDefectReplacementItem->sales_quantity > $new_sales_quantity) { $stock->quantity += $oldDefectReplacementItem->sales_quantity - $new_sales_quantity; //Add stock } elseif ($oldDefectReplacementItem->sales_quantity < $new_sales_quantity) { $sales_quantity = $new_sales_quantity - $oldDefectReplacementItem->sales_quantity; if ($stock->quantity < $sales_quantity) { Session()->flash('warning_message', 'Insufficient stock!.'); throw new \Exception(); } $stock->quantity -= $sales_quantity; //Sub stock } } } elseif ($oldDefectReplacementItem->sales_unit_type == 2) { if ($new_product['sales_unit_type'] == 1) { $new_sales_quantity = $oldDefectReplacementItem->sales_quantity / $new_product['weight'] * $new_product['length']; if ($new_sales_quantity > $new_product['sales_quantity']) { $stock->quantity += $new_sales_quantity - $new_product['sales_quantity']; $stock->quantity += $new_sales_quantity - $new_product['sales_quantity']; //Add stock } elseif ($new_sales_quantity < $new_product['sales_quantity']) { $sales_quantity = $new_product['sales_quantity'] - $new_sales_quantity; //Sub stock if ($stock->quantity < $sales_quantity) { Session()->flash('warning_message', 'Insufficient stock!.'); throw new \Exception(); } $stock->quantity -= $sales_quantity; //Sub stock } } elseif ($new_product['sales_unit_type'] == 2) { $old_sales_quantity = $oldDefectReplacementItem->sales_quantity / $new_product['weight'] * $new_product['length']; $new_sales_quantity = $new_product['sales_quantity'] / $new_product['weight'] * $new_product['length']; if ($old_sales_quantity > $new_sales_quantity) { $stock->quantity += $old_sales_quantity - $new_sales_quantity; //Add stock } elseif ($old_sales_quantity < $new_sales_quantity) { $sales_quantity = $new_sales_quantity - $old_sales_quantity; if ($stock->quantity < $sales_quantity) { Session()->flash('warning_message', 'Insufficient stock!.'); throw new \Exception(); } $stock->quantity -= $sales_quantity; //Sub stock } } } $stock->updated_by = $user->id; $stock->updated_at = $time; $stock->update(); } } }); } catch (\Exception $e) { Session()->flash('error_message', 'Defect receive update not success. Please try again.'); return Redirect::back(); } Session()->flash('flash_message', 'Defect receive updated successfully.'); return redirect('receive_defect'); }
/** * Delete the specified group * * @param Material $material * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function destroy(Material $material) { $this->authorize('delete_materials'); $material->delete(); flash()->success('Material Deleted', 'The material has been removed'); return redirect('material'); }