-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomUtils.php
More file actions
60 lines (53 loc) · 2.6 KB
/
Copy pathCustomUtils.php
File metadata and controls
60 lines (53 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Lambda\Dataform;
use Illuminate\Support\Facades\DB;
trait CustomUtils
{
public function customCallTrigger($action, $data,$subdata=null,$parentID,$status)
{
switch ($action) {
case 'beforeInsertDeleteOld':
if($data->model=='product_hasalt')
{
$oldbaraas =DB::table('product_hasalt')->where($data->parent, $parentID)->get();
if($oldbaraas){
foreach($oldbaraas as $oldbaraa){
DB::table('products')->where('id',$oldbaraa->baraaid)->increment('counter',$oldbaraa->counter);
}}
}
break;
case 'beforeInsert':
if($data->model=='product_hasalt')
{
$productprev=DB::table('products')->where('id',$data['baraaid'])->first();
$sd['customdate']=\Carbon\Carbon::now();
DB::table('products')->where('id',$sd['baraaid'])->decrement('counter',$sd['counter']);
$productnow=DB::table('products')->where('id',$sd['baraaid'])->first();
if($status=='store')
{
DB::table('products_logs')->insert([
'counter_prev'=>$productprev->counter,
'counter_now'=>$productnow->counter,
'name_prev'=>$productprev->name,
'name'=>$productnow->name,
'customdate'=>$sd['customdate'],
'username'=>Auth()->user()->name,
'desc'=> Auth()->user()->name . ':' . $sd['costumerid'] . '-хэрэглэгчид ' . $sd['counter'] . ' ширхэг бараа олгосон'
]);
}
else if($status=='update'){
DB::table('products_logs')->insert([
'counter_prev'=>$productprev->counter,
'counter_now'=>$productnow->counter,
'name_prev'=>$productprev->name,
'name'=>$productnow->name,
'customdate'=>$sd['customdate'],
'username'=>Auth()->user()->name,
'desc'=> Auth()->user()->name . ':' . $sd['costumerid'] . '-хэрэглэгчид ' . $sd['counter'] . ' ширхэг бараанд засвар хийсэн'
]);
}
}
break;
}
}
}