3 * SFX express delivery formant..
6 require_once 'Pman/Xtuple/Reports/Base.php';
8 class Pman_Xtuple_Reports_SalesOrderBookingDetail extends Pman_Xtuple_Reports_Base
14 $coitem = DB_DataObject::factory('coitem');
16 $coitem->joinAddItem();
17 $coitem->joinAddCust();
21 cntct AS join_billto_cntct
23 join_billto_cntct.cntct_id = join_coitem_cohead_id_cohead_id.cohead_billto_cntct_id
26 cntct AS join_shipto_cntct
28 join_shipto_cntct.cntct_id = join_coitem_cohead_id_cohead_id.cohead_shipto_cntct_id
30 vendaddrinfo AS join_shipto_vendaddrinfo
32 join_shipto_vendaddrinfo.vendaddr_addr_id = join_shipto_cntct.cntct_addr_id
34 vend AS join_shipto_vend
36 join_shipto_vend.vend_id = join_shipto_vendaddrinfo.vendaddr_vend_id
41 $cntct = DB_DataObject::Factory('cntct');
42 $coitem->selectAs($cntct, 'billto_%s', 'join_billto_cntct');
44 $cntct = DB_DataObject::Factory('cntct');
45 $coitem->selectAs($cntct, 'shipto_%s', 'join_shipto_cntct');
48 COALESCE(join_shipto_vend.vend_name, '') as vend_name,
49 COALESCE(join_shipto_vendaddrinfo.vendaddr_code, '') as vendaddr_code
53 $coitem->whereAddIn("coitem_cohead_id", explode(',',$_REQUEST['cohead_id']), 'int');
55 $coitem->orderBy('coitem_id ASC');
57 $count = $coitem->count();
59 $items = $coitem->fetchAll();
61 require_once 'Pman/Core/SimpleExcel.php';
65 array('訂單序號','center'),
66 array('收件方信息','center'),
68 array('商品資訊','center'),
70 array('附加服務','center'),
77 $merged_ranges = array(
85 $x = new Pman_Core_SimpleExcel(
86 array($items,array()),
92 'center' => array('Align'=>'center'),
94 'workbook' => 'Sales Orders',
97 'merged_ranges' => $merged_ranges,
102 'dataIndex' => 'coitem_id',
106 'dataFormat' => 'string',
108 'dataIndex' => 'coitem_cohead_id_cohead_shiptoname',
109 'format' => 'center',
113 'dataFormat' => 'string',
115 'dataIndex' => 'billto_cntct_phone',
116 'format' => 'center',
120 'dataFormat' => 'string',
122 'dataIndex' => 'shipto_cntct_phone2',
123 'format' => 'center',
126 'header' => '收件詳細地址',
127 'dataFormat' => 'string',
129 'dataIndex' => 'coitem_cohead_id_cohead_shiptoaddress1',
130 'format' => 'center',
131 'txtrenderer' => function( $v, $worksheet, $row, $col, $o) {
133 $address .= strlen($o->vend_name) ? "[{$o->vend_name}]" : '';
134 $address .= ($v) ? preg_replace('/,|\n/', '|', $v) : '';
135 $address .= ($o->coitem_cohead_id_cohead_shiptoaddress2) ? "|" . preg_replace('/,|\n/', '|', $o->coitem_cohead_id_cohead_shiptoaddress2) : '';
136 $address .= ($o->coitem_cohead_id_cohead_shiptoaddress3) ? "|" . preg_replace('/,|\n/', '|', $o->coitem_cohead_id_cohead_shiptoaddress3) : '';
137 $address .= ($o->coitem_cohead_id_cohead_shiptoaddress4) ? "|" . preg_replace('/,|\n/', '|', $o->coitem_cohead_id_cohead_shiptoaddress4) : '';
138 $address .= ($o->coitem_cohead_id_cohead_shiptoaddress5) ? "|" . preg_replace('/,|\n/', '|', $o->coitem_cohead_id_cohead_shiptoaddress5) : '';
139 $address .= ($o->coitem_cohead_id_cohead_shiptocity) ? "|" . preg_replace('/,|\n/', '|', $o->coitem_cohead_id_cohead_shiptocity) : '';
140 $address .= ($o->coitem_cohead_id_cohead_shiptostate) ? "|" . preg_replace('/,|\n/', '|', $o->coitem_cohead_id_cohead_shiptostate) : '';
141 $address .= ($o->coitem_cohead_id_cohead_shiptozipcode) ? "|" . preg_replace('/,|\n/', '|', $o->coitem_cohead_id_cohead_shiptozipcode) : '';
142 $address .= ($o->coitem_cohead_id_cohead_shiptocountry) ? "|" . preg_replace('/,|\n/', '|', $o->coitem_cohead_id_cohead_shiptocountry) : '';
143 $address .= strlen($o->vendaddr_code) ? "({$o->vendaddr_code})" : '';
150 'dataFormat' => 'string',
153 'format' => 'center',
157 'dataFormat' => 'string',
159 'dataIndex' => 'itemsite_id_item_number',
160 'format' => 'center',
164 'dataFormat' => 'number',
166 'dataIndex' => 'coitem_qtyord',
170 'dataFormat' => 'string',
173 'format' => 'center',
177 'dataFormat' => 'string',
180 'format' => 'center',
184 'dataFormat' => 'string',
187 'format' => 'center',
191 'dataFormat' => 'string',
194 'format' => 'center',
198 'dataFormat' => 'string',
201 'format' => 'center',
205 'dataFormat' => 'string',
208 'format' => 'center',
212 'dataFormat' => 'string',
215 'format' => 'center',
219 'dataFormat' => 'string',
222 'format' => 'center',
227 'dataFormat' => 'string',
229 'dataIndex' => 'coitem_cohead_id_cohead_number',
230 'format' => 'center',
231 'txtrenderer' => function( $v, $worksheet, $row, $col, $o) {
239 'dataFormat' => 'string',
242 'format' => 'center',
246 'dataFormat' => 'string',
249 'format' => 'center',
253 'dataFormat' => 'string',
256 'format' => 'center',
261 'workbook' => 'COUNT',
279 $x->send("order delivery report - ".date('Y-m-d').'.xls');
281 // if (!empty($this->workbook)) {
282 // $this->workbook->close();
283 // $this->workbook = false;
286 // require_once 'File/Convert.php';
287 // $fc= new File_Convert($x->outfile2, "application/vnd.ms-excel");
288 // $fn = $fc->convert("application/vnd.ms-excel");
290 // $attachment = new stdClass();
291 // $attachment->ext = 'application/vnd.ms-excel';
292 // $attachment->file = chunk_split(base64_encode(file_get_contents($fn)));
293 // $attachment->filename = $cohead->cohead_number.'-'.date('Y-m-d').'.xls';
297 // $data = new stdClass();
298 // $data->subject = $cohead->cohead_number . ' Order Booking Detail';
299 // $data->body = $cohead->cohead_number . ' Order Booking Detail is Attached';
301 // require_once 'Pman/Core/Mailer.php';
303 // $template = 'SalesOrderBookingDetail';
305 // $random_hash = md5(date('r', time()));
308 // $r = new Pman_Core_Mailer(array(
309 // 'template'=> $template,
311 // 'contents' => array(
312 // 'random_hash' => $random_hash,
313 // 'person' => $cohead->cohead_shipto_cntct_email,
315 // 'attach' => $attachment
320 // $sent = $r->send();
322 // if(!is_object($sent)){
323 // $this->jok('SUCCESS');
325 // $this->jerr('error!!:' . $sent->toString());