Skip to content

Commit 2531a38

Browse files
Update Inv_production_orderController.php
1 parent 8e7eec7 commit 2531a38

File tree

1 file changed

+0
-307
lines changed

1 file changed

+0
-307
lines changed
Lines changed: 0 additions & 307 deletions
Original file line numberDiff line numberDiff line change
@@ -1,308 +1 @@
1-
<?php
2-
//لاتنسونا من صالح الدعاء وجزاكم الله خيرا
3-
//أخي الكريم هذا الكود هو اول 100 ساعة بالكورس الي نهاية الدورة الفيدو رقم 190- اما باقي أكواد الدورة الثانية للتطوير النظام موجوده بالدورة ولابد ان تكتبها بنفسك لأهميتها وللإستفادة
4-
//حجم الدورة المتوقع هو 350 ساعة - الاشتراك بكورس يودمي له مميزات الحصول علي كود الدورة الاولي الي الفيدو 351 لأول 190 ساعه بالدورة
5-
//تبدأ الدورة الثانية للتطوير من الفيدو 351 وهي متاحه علي الانتساب او كورس يودمي
6-
namespace App\Http\Controllers\Admin;
7-
use App\Http\Controllers\Controller;
8-
use Illuminate\Http\Request;
9-
use App\Models\Admin;
10-
use App\Models\Inv_production_order;
11-
use App\Http\Requests\inv_production_orderRequest;
12-
use App\Models\Inv_stores_inventory;
131

14-
class Inv_production_orderController extends Controller
15-
{
16-
public function index(){
17-
try{
18-
$com_code=auth()->user()->com_code;
19-
$data=get_cols_where_p(new Inv_production_order(),array("*"),array("com_code"=>$com_code),'id','DESC',PAGINATION_COUNT);
20-
if (!empty($data)) {
21-
foreach ($data as $info) {
22-
$info->added_by_admin = Admin::where('id', $info->added_by)->value('name');
23-
if ($info->updated_by > 0 and $info->updated_by != null) {
24-
$info->updated_by_admin = Admin::where('id', $info->updated_by)->value('name');
25-
}
26-
if ($info->is_approved==1) {
27-
$info->approved_by_admin = Admin::where('id', $info->approved_by)->value('name');
28-
}
29-
if ($info->is_closed==1) {
30-
$info->closed_by_admin = Admin::where('id', $info->closed_by)->value('name');
31-
}
32-
33-
34-
}
35-
}
36-
return view('admin.inv_production_order.index',['data'=>$data]);
37-
}catch(\Exception $ex){
38-
return redirect()->back()->with(['error'=>'عفوا حدث خطأ ما']);
39-
}
40-
}
41-
public function create(){
42-
return view('admin.inv_production_order.create');
43-
}
44-
public function store(inv_production_orderRequest $request)
45-
{
46-
try {
47-
$com_code = auth()->user()->com_code;
48-
$row = get_cols_where_row_orderby(new Inv_production_order(), array("auto_serial"), array("com_code" => $com_code), 'id', 'DESC');
49-
if (!empty($row)) {
50-
$data['auto_serial'] = $row['auto_serial'] + 1;
51-
} else {
52-
$data['auto_serial'] = 1;
53-
}
54-
$data['production_plane'] = $request->production_plane;
55-
$data['production_plan_date'] = $request->production_plan_date;
56-
$data['created_at'] = date("Y-m-d H:i:s");
57-
$data['added_by'] = auth()->user()->id;
58-
$data['com_code'] = $com_code;
59-
$data['date'] = date("Y-m-d");
60-
insert(new Inv_production_order(),$data);
61-
return redirect()->route('admin.inv_production_order.index')->with(['success' => 'لقد تم اضافة البيانات بنجاح']);
62-
} catch (\Exception $ex) {
63-
return redirect()->back()
64-
->with(['error' => 'عفوا حدث خطأ ما' . $ex->getMessage()])
65-
->withInput();
66-
}
67-
}
68-
69-
public function edit($id)
70-
{
71-
$com_code = auth()->user()->com_code;
72-
$data = get_cols_where_row(new Inv_production_order(), array("*"), array("id" => $id, "com_code" => $com_code));
73-
if (empty($data)) {
74-
return redirect()->route('admin.inv_production_order.index')->with(['error' => 'عفوا غير قادر علي الوصول الي البيانات المطلوبة !!']);
75-
}
76-
if ($data['is_closed'] == 1) {
77-
return redirect()->route('admin.inv_production_order.index')->with(['error' => 'عفوا لايمكن التحديث علي فاتورة معتمدة ومؤرشفة']);
78-
}
79-
return view('admin.inv_production_order.edit', ['data' => $data]);
80-
81-
82-
}
83-
84-
public function update($id, inv_production_orderRequest $request)
85-
{
86-
try {
87-
$com_code = auth()->user()->com_code;
88-
$data = get_cols_where_row(new Inv_production_order(), array("*"), array("id" => $id, "com_code" => $com_code));
89-
if (empty($data)) {
90-
return redirect()->route('admin.inv_production_order.index')->with(['error' => 'عفوا غير قادر علي الوصول الي البيانات المطلوبة !!']);
91-
}
92-
if($data['is_closed'] == 1) {
93-
return redirect()->route('admin.inv_production_order.index')->with(['error' => 'عفوا لايمكن التحديث علي فاتورة معتمدة ومؤرشفة']);
94-
}
95-
96-
$data_to_update['production_plan_date'] = $request->production_plan_date;
97-
$data_to_update['production_plane'] = $request->production_plane;
98-
$data_to_update['updated_by'] = auth()->user()->id;
99-
$data_to_update['updated_at'] = date("Y-m-d H:i:s");
100-
update(new Inv_production_order(), $data_to_update, array("id" => $id, "com_code" => $com_code));
101-
return redirect()->route('admin.inv_production_order.index', $id)->with(['success' => 'لقد تم تحديث البيانات بنجاح']);
102-
} catch (\Exception $ex) {
103-
return redirect()->back()
104-
->with(['error' => 'عفوا حدث خطأ ما' . $ex->getMessage()])
105-
->withInput();
106-
}
107-
}
108-
109-
110-
public function delete($id)
111-
{
112-
try {
113-
$com_code = auth()->user()->com_code;
114-
$data = get_cols_where_row(new Inv_production_order(), array("is_closed"), array("id" => $id, "com_code" => $com_code));
115-
if (empty($data)) {
116-
return redirect()->back()
117-
->with(['error' => 'عفوا حدث خطأ ما']);
118-
}
119-
if ($data['is_closed'] == 1) {
120-
return redirect()->back()
121-
->with(['error' => 'عفوا لايمكن حذف أمر تشغيل معتمد ومؤرشف ']);
122-
}
123-
//هنا حنعمل مستقبلا التشيك علي عدم استخدامه في اوامر الصرف الداخلية من مخازن الخامات للورش
124-
125-
$flag = delete(new Inv_production_order(), array("id" => $id, "com_code" => $com_code));
126-
if ($flag) {
127-
return redirect()->route('admin.inv_production_order.index')->with(['success' => 'لقد تم حذف البيانات بنجاح']);
128-
}
129-
} catch (\Exception $ex) {
130-
return redirect()->back()
131-
->with(['error' => 'عفوا حدث خطأ ما' . $ex->getMessage()]);
132-
}
133-
}
134-
135-
public function show_more_detials(Request $request)
136-
{
137-
if ($request->ajax()) {
138-
$com_code = auth()->user()->com_code;
139-
$data = get_cols_where_row(new Inv_production_order(), array("*"), array("id" => $request->id, "com_code" => $com_code));
140-
if (!empty($data)) {
141-
if($data['updated_by']>0)
142-
{
143-
$data['updated_by_admin'] = Admin::where('id', $data['updated_by'])->value('name');
144-
}
145-
146-
}
147-
return view('admin.inv_production_order.show_more_detials', ['data' => $data]);
148-
149-
}
150-
}
151-
152-
public function do_approve($id)
153-
{
154-
try {
155-
$com_code = auth()->user()->com_code;
156-
$data = get_cols_where_row(new Inv_production_order(), array("is_approved"), array("id" => $id, "com_code" => $com_code));
157-
if (empty($data)) {
158-
return redirect()->back()
159-
->with(['error' => 'عفوا حدث خطأ ما']);
160-
}
161-
if ($data['is_closed'] == 1) {
162-
return redirect()->back()
163-
->with(['error' => 'عفوا لايمكن حذف أمر تشغيل معتمد ومؤرشف ']);
164-
}
165-
if ($data['is_approved'] == 1) {
166-
return redirect()->back()
167-
->with(['error' => 'عفوا هذا الامر بالفعل معتمد من قبل ! ']);
168-
}
169-
170-
$data_to_update['is_approved'] = 1;
171-
$data_to_update['approved_by'] = auth()->user()->id;
172-
$data_to_update['approved_at'] = date("Y-m-d H:i:s");
173-
$flag=update(new Inv_production_order(), $data_to_update, array("id" => $id, "com_code" => $com_code));
174-
175-
if ($flag) {
176-
return redirect()->route('admin.inv_production_order.index')->with(['success' => 'لقد تم اعتماد امر التشغيل بنجاح']);
177-
}else{
178-
return redirect()->back()
179-
->with(['error' => ' عفوا لم يتم العملية من فضلك حاول مرةأخري ']);
180-
}
181-
} catch (\Exception $ex) {
182-
return redirect()->back()
183-
->with(['error' => 'عفوا حدث خطأ ما' . $ex->getMessage()]);
184-
}
185-
}
186-
187-
public function do_closes_archive($id)
188-
{
189-
try {
190-
$com_code = auth()->user()->com_code;
191-
$data = get_cols_where_row(new Inv_production_order(), array("is_approved","is_closed"), array("id" => $id, "com_code" => $com_code));
192-
if (empty($data)) {
193-
return redirect()->back()
194-
->with(['error' => 'عفوا حدث خطأ ما']);
195-
}
196-
if ($data['is_approved'] == 0) {
197-
return redirect()->back()
198-
->with(['error' => 'عفوا لايمكن اغلاق أمر تشغيل غير معتمد ']);
199-
}
200-
if ($data['is_closed'] == 1) {
201-
return redirect()->back()
202-
->with(['error' => 'عفوا هذا الامر بالفعل مغلق من قبل ! ']);
203-
}
204-
//مستقبلا حنشيك علي استخدامه بالفعل داخل حركات ورش الانتاج
205-
$data_to_update['is_closed'] = 1;
206-
$data_to_update['closed_by'] = auth()->user()->id;
207-
$data_to_update['closed_at'] = date("Y-m-d H:i:s");
208-
$flag=update(new Inv_production_order(), $data_to_update, array("id" => $id, "com_code" => $com_code));
209-
210-
if ($flag) {
211-
return redirect()->route('admin.inv_production_order.index')->with(['success' => 'لقد تم اعتماد امر التشغيل بنجاح']);
212-
}else{
213-
return redirect()->back()
214-
->with(['error' => ' عفوا لم يتم العملية من فضلك حاول مرةأخري ']);
215-
}
216-
} catch (\Exception $ex) {
217-
return redirect()->back()
218-
->with(['error' => 'عفوا حدث خطأ ما' . $ex->getMessage()]);
219-
}
220-
}
221-
222-
public function ajax_search(Request $request)
223-
{
224-
if ($request->ajax()) {
225-
$com_code = auth()->user()->com_code;
226-
227-
$search_by_text = $request->search_by_text;
228-
$close_search = $request->close_search;
229-
$approve_search = $request->approve_search;
230-
$from_date_search = $request->from_date_search;
231-
$to_date_search = $request->to_date_search;
232-
if ($search_by_text == '') {
233-
//دائما true
234-
$field1 = "id";
235-
$operator1 = ">";
236-
$value1 = 0;
237-
} else {
238-
$field1 = "auto_serial";
239-
$operator1 = "=";
240-
$value1 = $search_by_text;
241-
}
242-
if ($close_search == 'all') {
243-
//دائما true
244-
$field2 = "id";
245-
$operator2 = ">";
246-
$value2 = 0;
247-
} else {
248-
$field2 = "is_closed";
249-
$operator2 = "=";
250-
$value2 = $close_search;
251-
}
252-
253-
if ($approve_search == 'all') {
254-
//دائما true
255-
$field3 = "id";
256-
$operator3 = ">";
257-
$value3 = 0;
258-
} else {
259-
$field3 = "is_approved";
260-
$operator3 = "=";
261-
$value3 = $approve_search;
262-
}
263-
264-
if ($from_date_search == '') {
265-
//دائما true
266-
$field4 = "id";
267-
$operator4 = ">";
268-
$value4= 0;
269-
} else {
270-
$field4 = "production_plan_date";
271-
$operator4 = ">=";
272-
$value4 = $from_date_search;
273-
}
274-
275-
if ($to_date_search == '') {
276-
//دائما true
277-
$field5 = "id";
278-
$operator5 = ">";
279-
$value5= 0;
280-
} else {
281-
$field5 = "production_plan_date";
282-
$operator5 = "<=";
283-
$value5 = $to_date_search;
284-
}
285-
286-
$data = inv_production_order::where($field1, $operator1, $value1)->where($field2, $operator2, $value2)->where($field3, $operator3, $value3)->where($field4, $operator4, $value4)->where($field5, $operator5, $value5)->where('com_code','=',$com_code)->orderBy('id', 'DESC')->paginate(PAGINATION_COUNT);
287-
if (!empty($data)) {
288-
foreach ($data as $info) {
289-
$info->added_by_admin = Admin::where('id', $info->added_by)->value('name');
290-
if ($info->updated_by > 0 and $info->updated_by != null) {
291-
$info->updated_by_admin = Admin::where('id', $info->updated_by)->value('name');
292-
}
293-
if ($info->is_approved==1) {
294-
$info->approved_by_admin = Admin::where('id', $info->approved_by)->value('name');
295-
}
296-
if ($info->is_closed==1) {
297-
$info->closed_by_admin = Admin::where('id', $info->closed_by)->value('name');
298-
}
299-
300-
301-
}
302-
}
303-
return view('admin.inv_production_order.ajax_search', ['data' => $data]);
304-
}
305-
}
306-
307-
308-
}

0 commit comments

Comments
 (0)