Skip to content

Commit 8e7eec7

Browse files
Update Inv_production_linesController.php
1 parent 60b8ead commit 8e7eec7

File tree

1 file changed

+0
-272
lines changed

1 file changed

+0
-272
lines changed
Lines changed: 0 additions & 272 deletions
Original file line numberDiff line numberDiff line change
@@ -1,273 +1 @@
1-
<?php
2-
//لاتنسونا من صالح الدعاء وجزاكم الله خيرا
3-
//أخي الكريم هذا الكود هو اول 100 ساعة بالكورس الي نهاية الدورة الفيدو رقم 190- اما باقي أكواد الدورة الثانية للتطوير النظام موجوده بالدورة ولابد ان تكتبها بنفسك لأهميتها وللإستفادة
4-
//حجم الدورة المتوقع هو 350 ساعة - الاشتراك بكورس يودمي له مميزات الحصول علي كود الدورة الاولي الي الفيدو 351 لأول 190 ساعه بالدورة
5-
//تبدأ الدورة الثانية للتطوير من الفيدو 351 وهي متاحه علي الانتساب او كورس يودمي
6-
namespace App\Http\Controllers\Admin;
71

8-
use App\Http\Controllers\Controller;
9-
use App\Models\Inv_production_lines;
10-
use App\Models\Admin;
11-
use App\Models\Account;
12-
use App\Models\Admin_panel_setting;
13-
use Illuminate\Http\Request;
14-
use App\Http\Requests\Inv_production_linesRequest;
15-
use App\Http\Requests\Inv_production_linesU_Request;
16-
17-
18-
19-
class Inv_production_linesController extends Controller
20-
{
21-
public function index()
22-
{
23-
$com_code = auth()->user()->com_code;
24-
$data = get_cols_where_p(new Inv_production_lines(), array("*"), array("com_code" => $com_code), 'id', 'DESC', PAGINATION_COUNT);
25-
if (!empty($data)) {
26-
foreach ($data as $info) {
27-
$info->added_by_admin = Admin::where('id', $info->added_by)->value('name');
28-
if ($info->updated_by > 0 and $info->updated_by != null) {
29-
$info->updated_by_admin = Admin::where('id', $info->updated_by)->value('name');
30-
}
31-
}
32-
}
33-
return view('admin.inv_production_lines.index', ['data' => $data]);
34-
}
35-
36-
37-
38-
public function create()
39-
{
40-
return view('admin.inv_production_lines.create');
41-
}
42-
43-
44-
public function store(Inv_production_linesRequest $request)
45-
{
46-
try {
47-
$com_code = auth()->user()->com_code;
48-
//check if not exsits for name
49-
$checkExists_name = get_cols_where_row(new Inv_production_lines(), array("id"), array('name' => $request->name, 'com_code' => $com_code));
50-
if (!empty($checkExists_name)) {
51-
return redirect()->back()
52-
->with(['error' => 'عفوا اسم خط الانتج مسجل من قبل'])
53-
->withInput();
54-
}
55-
//set Inv_production_lines code
56-
$row = get_cols_where_row_orderby(new Inv_production_lines(), array("production_lines_code"), array("com_code" => $com_code), 'id', 'DESC');
57-
if (!empty($row)) {
58-
$data_insert['production_lines_code'] = $row['production_lines_code'] + 1;
59-
} else {
60-
$data_insert['production_lines_code'] = 1;
61-
}
62-
//set account number
63-
$row = get_cols_where_row_orderby(new Account(), array("account_number"), array("com_code" => $com_code), 'id', 'DESC');
64-
if (!empty($row)) {
65-
$data_insert['account_number'] = $row['account_number'] + 1;
66-
} else {
67-
$data_insert['account_number'] = 1;
68-
}
69-
$data_insert['name'] = $request->name;
70-
$data_insert['address'] = $request->address;
71-
$data_insert['start_balance_status'] = $request->start_balance_status;
72-
if ($data_insert['start_balance_status'] == 1) {
73-
//credit
74-
$data_insert['start_balance'] = $request->start_balance * (-1);
75-
} elseif ($data_insert['start_balance_status'] == 2) {
76-
//debit
77-
$data_insert['start_balance'] = $request->start_balance;
78-
if ($data_insert['start_balance'] < 0) {
79-
$data_insert['start_balance'] = $data_insert['start_balance'] * (-1);
80-
}
81-
} elseif ($data_insert['start_balance_status'] == 3) {
82-
//balanced
83-
$data_insert['start_balance'] = 0;
84-
} else {
85-
$data_insert['start_balance_status'] = 3;
86-
$data_insert['start_balance'] = 0;
87-
}
88-
$data_insert['phones'] = $request->phones;
89-
$data_insert['current_balance'] = $data_insert['start_balance'];
90-
$data_insert['notes'] = $request->notes;
91-
$data_insert['active'] = $request->active;
92-
$data_insert['added_by'] = auth()->user()->id;
93-
$data_insert['created_at'] = date("Y-m-d H:i:s");
94-
$data_insert['date'] = date("Y-m-d");
95-
$data_insert['com_code'] = $com_code;
96-
$flag = insert(new Inv_production_lines(), $data_insert);
97-
if ($flag) {
98-
//insert into accounts
99-
$data_insert_account['name'] = $request->name;
100-
$data_insert_account['start_balance_status'] = $request->start_balance_status;
101-
if ($data_insert_account['start_balance_status'] == 1) {
102-
//credit
103-
$data_insert_account['start_balance'] = $request->start_balance * (-1);
104-
} elseif ($data_insert_account['start_balance_status'] == 2) {
105-
//debit
106-
$data_insert_account['start_balance'] = $request->start_balance;
107-
if ($data_insert_account['start_balance'] < 0) {
108-
$data_insert_account['start_balance'] = $data_insert_account['start_balance'] * (-1);
109-
}
110-
} elseif ($data_insert_account['start_balance_status'] == 3) {
111-
//balanced
112-
$data_insert_account['start_balance'] = 0;
113-
} else {
114-
$data_insert_account['start_balance_status'] = 3;
115-
$data_insert_account['start_balance'] = 0;
116-
}
117-
$data_insert_account['current_balance'] = $data_insert_account['start_balance'];
118-
$production_lines_parent_account = get_field_value(new Admin_panel_setting(), "production_lines_parent_account", array('com_code' => $com_code));
119-
$data_insert_account['notes'] = $request->notes;
120-
$data_insert_account['parent_account_number'] = $production_lines_parent_account;
121-
$data_insert_account['is_parent'] = 0;
122-
$data_insert_account['account_number'] = $data_insert['account_number'];
123-
$data_insert_account['account_type'] = 5;
124-
$data_insert_account['active'] = $request->active;
125-
$data_insert_account['added_by'] = auth()->user()->id;
126-
$data_insert_account['created_at'] = date("Y-m-d H:i:s");
127-
$data_insert_account['date'] = date("Y-m-d");
128-
$data_insert_account['com_code'] = $com_code;
129-
$data_insert_account['other_table_FK'] = $data_insert['production_lines_code'];
130-
$flag = insert(new Account(), $data_insert_account);
131-
}
132-
return redirect()->route('admin.inv_production_lines.index')->with(['success' => 'لقد تم اضافة البيانات بنجاح']);
133-
} catch (\Exception $ex) {
134-
return redirect()->back()
135-
->with(['error' => 'عفوا حدث خطأ ما' . $ex->getMessage()])
136-
->withInput();
137-
}
138-
}
139-
140-
public function edit($id)
141-
{
142-
$com_code = auth()->user()->com_code;
143-
$data = get_cols_where_row(new Inv_production_lines(), array("*"), array("id" => $id, "com_code" => $com_code));
144-
if (empty($data)) {
145-
return redirect()->route('admin.inv_production_lines.index')->with(['error' => 'عفوا غير قادر علي الوصول الي البيانات المطلوبة !!']);
146-
}
147-
return view('admin.inv_production_lines.edit', ['data' => $data]);
148-
}
149-
150-
public function update($id, Inv_production_linesU_Request $request)
151-
{
152-
try {
153-
$com_code = auth()->user()->com_code;
154-
$data = get_cols_where_row(new Inv_production_lines(), array("id", "account_number", "production_lines_code"), array("id" => $id, "com_code" => $com_code));
155-
if (empty($data)) {
156-
return redirect()->route('admin.inv_production_lines.index')->with(['error' => 'عفوا غير قادر علي الوصول الي البيانات المطلوبة !!']);
157-
}
158-
$checkExists = Inv_production_lines::where(['name' => $request->name, 'com_code' => $com_code])->where('id', '!=', $id)->first();
159-
if ($checkExists != null) {
160-
return redirect()->back()
161-
->with(['error' => 'عفوا اسم خط الانتاج مسجل من قبل'])
162-
->withInput();
163-
}
164-
$data_to_update['name'] = $request->name;
165-
$data_to_update['phones'] = $request->phones;
166-
$data_to_update['address'] = $request->address;
167-
$data_to_update['notes'] = $request->notes;
168-
$data_to_update['active'] = $request->active;
169-
$data_to_update['updated_by'] = auth()->user()->id;
170-
$data_to_update['updated_at'] = date("Y-m-d H:i:s");
171-
$flag = update(new Inv_production_lines(), $data_to_update, array('id' => $id, 'com_code' => $com_code));
172-
if ($flag) {
173-
$data_to_update_account['name'] = $request->name;
174-
$data_to_update_account['updated_by'] = auth()->user()->id;
175-
$data_to_update_account['updated_at'] = date("Y-m-d H:i:s");
176-
$data_to_update_account['active']=$request->active;
177-
$flag = update(new Account(), $data_to_update_account, array('account_number' => $data['account_number'], 'other_table_FK' => $data['production_lines_code'], 'com_code' => $com_code, 'account_type' => 5));
178-
}
179-
return redirect()->route('admin.inv_production_lines.index')->with(['success' => 'لقد تم تحديث البيانات بنجاح']);
180-
} catch (\Exception $ex) {
181-
return redirect()->back()
182-
->with(['error' => 'عفوا حدث خطأ ما' . $ex->getMessage()])
183-
->withInput();
184-
}
185-
}
186-
187-
188-
public function ajax_search(Request $request)
189-
{
190-
if ($request->ajax()) {
191-
192-
$com_code = auth()->user()->com_code;
193-
$search_by_text = $request->search_by_text;
194-
$searchbyradio = $request->searchbyradio;
195-
$searchByBalanceStatus = $request->searchByBalanceStatus;
196-
$searchByactiveStatus = $request->searchByactiveStatus;
197-
$mirror['searchByBalanceStatus']=$searchByBalanceStatus ;
198-
199-
if ($search_by_text != '') {
200-
if ($searchbyradio == 'production_lines_code') {
201-
$field1 = "production_lines_code";
202-
$operator1 = "=";
203-
$value1 = $search_by_text;
204-
} elseif ($searchbyradio == 'account_number') {
205-
$field1 = "account_number";
206-
$operator1 = "=";
207-
$value1 = $search_by_text;
208-
} else {
209-
$field1 = "name";
210-
$operator1 = "like";
211-
$value1 = "%{$search_by_text}%";
212-
}
213-
} else {
214-
//true
215-
$field1 = "id";
216-
$operator1 = ">";
217-
$value1 = 0;
218-
}
219-
220-
if($searchByBalanceStatus=="all"){
221-
$field2 = "id";
222-
$operator2 = ">";
223-
$value2 = 0;
224-
}else{
225-
if($searchByBalanceStatus==1){
226-
$field2 = "current_balance";
227-
$operator2 = "<";
228-
$value2 = 0;
229-
230-
}elseif($searchByBalanceStatus==2){
231-
$field2 = "current_balance";
232-
$operator2 = ">";
233-
$value2 = 0;
234-
}else{
235-
$field2 = "current_balance";
236-
$operator2 = "=";
237-
$value2 = 0;
238-
}
239-
240-
}
241-
242-
if($searchByactiveStatus=="all"){
243-
$field3 = "id";
244-
$operator3 = ">";
245-
$value3 = 0;
246-
}else{
247-
248-
$field3 = "active";
249-
$operator3 = "=";
250-
$value3 = $searchByactiveStatus;
251-
}
252-
253-
254-
$data = Inv_production_lines::where($field1, $operator1, $value1)->where($field2, $operator2, $value2)->where($field3, $operator3, $value3)->where(['com_code' => $com_code])->orderBy('id', 'DESC')->paginate(PAGINATION_COUNT);
255-
if (!empty($data)) {
256-
foreach ($data as $info) {
257-
$info->added_by_admin = Admin::where('id', $info->added_by)->value('name');
258-
if ($info->updated_by > 0 and $info->updated_by != null) {
259-
$info->updated_by_admin = Admin::where('id', $info->updated_by)->value('name');
260-
}
261-
}
262-
}
263-
//General mirror
264-
$mirror['credit_sum']=Inv_production_lines::where($field1, $operator1, $value1)->where($field2, $operator2, $value2)->where("current_balance", "<", 0)->where($field3, $operator3, $value3)->where(['com_code' => $com_code])->sum('current_balance');
265-
$mirror['debit_sum']=Inv_production_lines::where($field1, $operator1, $value1)->where($field2, $operator2, $value2)->where("current_balance", ">", 0)->where($field3, $operator3, $value3)->where(['com_code' => $com_code])->sum('current_balance');
266-
$mirror['net']=$mirror['credit_sum']+$mirror['debit_sum'];
267-
return view('admin.inv_production_lines.ajax_search', ['data' => $data,'mirror'=>$mirror]);
268-
}
269-
}
270-
271-
272-
273-
}

0 commit comments

Comments
 (0)