2db47680
hexiaodong
chore: 初始提交 php 遗...
|
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
<?php
namespace app\admin\controller\kuerp;
use app\common\controller\Backend;
use think\Db;
/**
* 供应商对账单
*
* @icon fa fa-circle-o
*/
class SuppliersRecon extends Backend
{
/**
* AccountsReceivable模型对象
* @var \app\admin\model\kuerp\AccountsReceivable
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$setData = (new Goods())->getSetData();
$this->assign('set', $setData['setList']);
$this->assignconfig('set',$setData['setList']);
$this->assign('nowmenu', $setData['nowmenu']);
$this->model = new \app\admin\model\kuerp\AccountsReceivable;
$this->view->assign("businessTypeList", $this->model->getBusinessTypeList());
$this->view->assign("customers", $this->model->getCustomersList());
$this->view->assign("suppliers", $this->model->getSuppliersList());
$this->view->assign("saleList", $this->model->getSaleList());
}
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
$data = input();
$where = [];
$map = [];
if(isset($data['filter'])){
$filter = (array)json_decode($data['filter'], true);
$filter = $filter ? $filter : [];
if(!empty($filter['purchase_time'])){
$str = explode(' - ',$filter['purchase_time']);
$where['purchase_time'] = ["BETWEEN", [strtotime($str[0]),strtotime($str[1])]];
}
if(!empty($filter['suppliers_id'])){
$map['sp.id'] = trim($filter['suppliers_id']);
}
if(!empty($filter['id'])){
$map['sp.id'] = ['<',$filter['id']];
}
}
$where = (new Goods())->setWhere($where);
$map = (new Goods())->setWhere($map,'sp');
$sup = Db::name('kuerp_suppliers')->alias('sp')
->join('kuerp_supplyertype gt','sp.supplyertype_id=gt.id')
->where($map)
->order('sp.supplyer_code asc')
->field('sp.id,sp.receive_account,sp.supplyer_code,sp.supplyer_name,gt.supplier_type_name,sp.opening_payable,sp.opening_prepayment')
->select();
$field = empty(input('field'))?'createtime':trim(input('field'));
$order = empty(input('sort'))?'ASC':trim(input('sort'));
//获取设置
$set= \think\Db::name('kuerp_sets')->field('type,name,value,is_checked,set')->select();
$setList = [];
foreach ($set as $set_k=>$set_v){
if(!empty($set_v['set'])){
$set_v['set'] = unserialize($set_v['set']);
}
$setList[$set_v['name']] = $set_v;
}
//数量价格格式化
$price_decimal = $setList['price_decimal']['value'];
$listarr = [];
$all_sale_money = 0;
$all_receivable = 0;
$all_cost = 0;
$all_real_money = 0;
$all_balance = 0;
foreach ($sup as $sup_k=>$sup_v){
$sale_money = 0;
$receivable = 0;
$cost = 0;
$real_money = 0;
$balance = 0;
$sup_v['receive_account'] = round($sup_v['opening_payable']-$sup_v['opening_prepayment'],$price_decimal);
$listarr[] = [
'customer_name' => $sup_v['supplyer_name'],
'purchase_time' => '',
'purchase_code' => '期初余额',
'business_type' => '',
'sale_money' => '',
'receivable' => '',
'amount' => '',
'cost' => '',
'real_money' => '',
'balance' => $sup_v['receive_account'],
'remark' => ''
];
$balance += $sup_v['receive_account'];
$list = Db::name('kuerp_accounts_copewith')
->where($where)
->where(['suppliers_id'=>$sup_v['id'],'business_type'=>['not in',[1,2]]])
->order([$field=>$order])
->select();
foreach ($list as $list_k=>$list_v){
if($list_v['business_type']==7){
$balance -= $list_v['receivable_money'];
$balance += $list_v['real_money'];
$sale_money -= $list_v['sale_money'];
$receivable -= $list_v['receivable_money'];
$cost -= $list_v['cost'];
$real_money -= $list_v['real_money'];
$listarr[] = [
'customer_name' => $sup_v['supplyer_name'],
'purchase_time' => !empty($list_v['purchase_time'])?date('Y-m-d',$list_v['purchase_time']):'',
'purchase_code' => $list_v['purchase_code'],
'business_type' => $list_v['business_type'],
'sale_money' => -$list_v['sale_money'],
'receivable' => -$list_v['receivable_money'],
'amount' => -$list_v['amount'],
'cost' => -$list_v['cost'],
'real_money' => -$list_v['real_money'],
'balance' => round($balance,$price_decimal),
'remark' => $list_v['remark'],
];
}else{
$balance += $list_v['receivable_money'];
$balance -= $list_v['real_money'];
$sale_money += $list_v['sale_money'];
$receivable += $list_v['receivable_money'];
$cost += $list_v['cost'];
$real_money += $list_v['real_money'];
$listarr[] = [
'customer_name' => $sup_v['supplyer_name'],
'purchase_time' => !empty($list_v['purchase_time'])?date('Y-m-d',$list_v['purchase_time']):'',
'purchase_code' => $list_v['purchase_code'],
'business_type' => $list_v['business_type'],
'sale_money' => $list_v['sale_money'],
'receivable' => $list_v['receivable_money'],
'amount' => $list_v['amount'],
'cost' => $list_v['cost'],
'real_money' => $list_v['real_money'],
'balance' => round($balance,$price_decimal),
'remark' => $list_v['remark'],
];
}
}
$listarr[] = [
'customer_name' => $sup_v['supplyer_name'],
'purchase_time' => '',
'purchase_code' => '小计',
'business_type' => '',
'sale_money' => round($sale_money,$price_decimal),
'receivable' => round($receivable,$price_decimal),
'amount' => '',
'cost' => round($cost,$price_decimal),
'real_money' => round($real_money,$price_decimal),
'balance' => round($balance,$price_decimal),
'remark' => ''
];
$all_sale_money += $sale_money;
$all_receivable += $receivable;
$all_cost += $cost;
$all_real_money += $real_money;
$all_balance += $balance;
}
$result = array("total" => sizeof($listarr),
"rows" => $listarr,
"all_sale_money" => $all_sale_money,
"all_receivable" => $all_receivable,
"all_cost" => $all_cost,
"all_real_money" => $all_real_money,
"all_balance" => $all_balance,
);
return json($result);
}
return $this->view->fetch();
}
}
|