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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
<?php
class PayeasePaymentSubmit extends BaseModel { protected $table = "payease_payment_submit";
public function supplier() { return $this->belongsTo('Supplier'); }
public function invoiceItems() { return $this->hasMany('InvoiceItem'); }
public function payeasePaymentDtls() { return $this->hasMany('PayeasePaymentDtl', 'payease_payment_submit_id', 'id'); }
public function currency() { return $this->belongsTo('Currency', 'currency_code', 'iso_code'); } /** * calculate the amount in base currency * @return float amount in base curreny of the details */ public function calcAmount() { $this->amount = 0; foreach ($this->payeasePaymentDtls as $key => $payeasePaymentDtl) { // TODO: can we combine different curreny payment in 1 report? $this->amount += $payeasePaymentDtl->amount; } return $this; }
public function supportApi() { return false; }
public function toXLS() { $xls = [ 'title_start_row' => 1, 'data_start_row' => 3, ];
$objPHPexcel = PHPExcel_IOFactory::load("resources/pg_settle_report.xls"); $objWorksheet = $objPHPexcel->getSheetByName('DOC');
// $headerFooter = "&LDate: {$request_param['date']} &CSales Report (Annual)"; // $objWorksheet->getHeaderFooter()->setOddHeader($headerFooter); // $objWorksheet->getHeaderFooter()->setEvenHeader($headerFooter);
$current_row = $xls['title_start_row']; $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit('Title', PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($this->createdate, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($this->code, PHPExcel_Cell_DataType::TYPE_STRING);
$current_row = $xls['data_start_row']; $header_row = $current_row; $settlement_amount = 0; foreach ($this->payeasePaymentDtls()->with('supplier')->where('payment_type', $this->from_paymentgateway)->orderBy('supplier_id')->get() as $payeasePaymentDtl) { $col = 0; $current_row++; $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit('Payment', PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->createdate, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->supplier->code, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->supplier->payease_sub_merchant_number, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->supplier->payease_bank_name, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->supplier->payease_bank_city, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->supplier->payease_bank_code, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->id, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->code, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->settlement_currency_code, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit(number_format($payeasePaymentDtl->settlement_amount, 2, '.', ''), PHPExcel_Cell_DataType::TYPE_NUMERIC); $settlement_amount += $payeasePaymentDtl->settlement_amount; }
$col = 0; $current_row++; $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit('Settlement', PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit($this->submitdate, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit($this->from_paymentgateway, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit($this->to_paymentgateway, PHPExcel_Cell_DataType::TYPE_STRING); $col += 5; $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit($this->currency_code, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit(number_format($settlement_amount, 2, '.', ''), PHPExcel_Cell_DataType::TYPE_NUMERIC);
if ($this->from_paymentgateway != $this->to_paymentgateway) { $current_row++; // b to a $header_row = $current_row; $settlement_amount = 0; foreach ($this->payeasePaymentDtls()->with('supplier')->where('payment_type', $this->to_paymentgateway)->orderBy('supplier_id')->get() as $payeasePaymentDtl) { $col = 0; $current_row++; $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit('Payment', PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->createdate, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->supplier->code, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->supplier->payease_sub_merchant_number, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->supplier->payease_bank_name, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->supplier->payease_bank_city, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->supplier->payease_bank_code, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->id, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->code, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit($payeasePaymentDtl->settlement_currency_code, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $current_row)->setValueExplicit(number_format($payeasePaymentDtl->settlement_amount, 2, '.', ''), PHPExcel_Cell_DataType::TYPE_NUMERIC); $settlement_amount += $payeasePaymentDtl->settlement_amount; }
$col = 0; $current_row++; $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit('Settlement', PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit($this->submitdate, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit($this->to_paymentgateway, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit($this->from_paymentgateway, PHPExcel_Cell_DataType::TYPE_STRING); $col += 5; $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit($this->currency_code, PHPExcel_Cell_DataType::TYPE_STRING); $objWorksheet->getCellByColumnAndRow($col++, $header_row)->setValueExplicit(number_format($settlement_amount, 2, '.', ''), PHPExcel_Cell_DataType::TYPE_NUMERIC); }
$current_row = $xls['data_start_row']; $header_row = $current_row;
foreach ($this->payeasePaymentDtls()->with('supplier')->where('payment_type', $this->from_paymentgateway)->orderBy('supplier_id')->get() as $payeasePaymentDtl) {
$settlement_amount += $payeasePaymentDtl->settlement_amount; }
$objPHPexcel->setActiveSheetIndex(0); return $objPHPexcel; }
public function toXML() { $xml = new SimpleXMLElement('<xml/>'); $settlements = $xml->addChild('settlements');
// a to b $settlement_amount = 0; $settlement = $settlements->addChild('settlement'); $settlement_header = $settlement->addChild('settlement_header'); $settlement_detail = $settlement->addChild('settlement_detail');
$payments = $settlement_detail->addChild('payments'); foreach ($this->payeasePaymentDtls()->with('supplier')->where('payment_type', $this->from_paymentgateway)->orderBy('supplier_id')->get() as $payeasePaymentDtl) { $payeasePaymentDtl->appendXML($payments, 'payment'); $settlement_amount += $payeasePaymentDtl->settlement_amount; }
$settlement_header->addChild('date', $this->submitdate); $settlement_header->addChild('from', $this->from_paymentgateway); $settlement_header->addChild('to', $this->to_paymentgateway); $settlement_header->addChild('currency', $this->currency_code); $settlement_header->addChild('amount', number_format($settlement_amount, 2, '.', ''));
if ($this->from_paymentgateway != $this->to_paymentgateway) { // b to a $settlement_amount = 0; $settlement = $settlements->addChild('settlement'); $settlement_header = $settlement->addChild('settlement_header'); $settlement_detail = $settlement->addChild('settlement_detail');
$payments = $settlement_detail->addChild('payments'); foreach ($this->payeasePaymentDtls()->with('supplier')->where('payment_type', $this->to_paymentgateway)->orderBy('supplier_id')->get() as $payeasePaymentDtl) { $payeasePaymentDtl->appendXML($payments, 'payment'); $settlement_amount += $payeasePaymentDtl->settlement_amount; }
$settlement_header->addChild('date', $this->submitdate); $settlement_header->addChild('from', $this->to_paymentgateway); $settlement_header->addChild('to', $this->from_paymentgateway); $settlement_header->addChild('currency', $this->settlement_currency_code); $settlement_header->addChild('amount', number_format($settlement_amount, 2, '.', '')); }
// <net> settlement using current exchange rate
return $xml; }
// public function doSubmit(Payease $api) // { // $supplier = $this->supplier; // // prepare v_data // $data = []; // foreach ($this->payeasePaymentDtls as $key => $payeasePaymentDtl) { // // TODO: can we combine different curreny payment in 1 report? // $data[] = [ // 'payease_bank_client_accountcode' => $supplier->payease_bank_client_accountcode, // 'payease_bank_client_name' => $supplier->payease_bank_client_name, // 'payease_bank_name' => $supplier->payease_bank_name, // 'payease_bank_province' => $supplier->payease_bank_province, // 'payease_bank_city' => $supplier->payease_bank_city, // 'amount' => $payeasePaymentDtl->amount, // 'supplier_tx_code' => $payeasePaymentDtl->id, // 'payease_bank_code' => $supplier->payease_bank_code, // ]; // }
// 5|750.00 // $5400001| 张三| 北京建行东四支行| 北京市| 北京市 |400.00|2001|105100000017 // $5400002| 李四| 天津建行西四支行| 天津市| 天津市 |200.00|2002|105100000017 // $5400003| 张三| 北京建行东四支行| 北京市| 北京市 |10.00|2001|105100000017 // $5400004| 张三| 北京建行东四支行| 北京市| 北京市 |40.00|2001|105100000017 // $5400005| 王五| 湖南工行长沙支行| 湖南省| 长沙市 |100.00|2003|102100099996
// $v_data = ''; // $v_data .= count($data) . '|' . $this->amount; // foreach ($data as $key => $tx) { // $v_data .= '$' . implode('|', $tx); // } // // vdump($v_data); // $this->request = $v_data;
// $this->response = $api->mer_payment_submit_utf8($v_data); // $this->fill([ // 'status' => $this->response->status, // 'submitdate' => timestamp(), // 'successdate' => $this->response->status == 1 ? timestamp() : null, // 'status' => $this->response->status, // ]);
// // switch ($this->response->status) { // // case '0': // // $ // // break;
// // default: // // # code... // // break; // // } // } }
|