Files
old-new-wiaas/backend/app/plugins/wiaas/includes/order/class-wiaas-procurement-order.php
2018-11-04 11:17:42 +01:00

99 lines
3.7 KiB
PHP

<?php
/**
*
* Procurement order is sent from admin /broker to product suppliers
*
* For now this system only needs to collect info for admin to generate this order in his own system
*
* Class Wiaas_Procurement_Order
*/
class Wiaas_Procurement_Order {
public static function init() {
}
public static function export_procurement_order($order_id) {
$order = wc_get_order($order_id);
$objPHPExcel = new PHPExcel();
$customer_user_id = $order->get_customer_id();
$organization_id = wiaas_get_user_organization_id($customer_user_id);
$customer_organization_info = wiaas_get_organization_info($organization_id);
$info = array(
'number' => $order->get_order_number(),
'project_number' => 'SE' . $order->get_order_number(),
'reference' => $order->get_meta('_wiaas_reference'),
'vat_code' => ! empty($customer_organization_info) ? $customer_organization_info['vat_code'] : '',
'customer_name' => ! empty($customer_organization_info) ? $customer_organization_info['name'] : '',
'delivery_address' => $order->get_shipping_address_1() . ',' .
$order->get_shipping_city() . ',' .
$order->get_shipping_country() . ',' .
$order->get_shipping_postcode(),
'delivery_full_name' => $order->get_formatted_shipping_full_name(),
'billing_address' => $order->get_billing_address_1() . ',' .
$order->get_billing_city() . ',' .
$order->get_billing_country() . ',' .
$order->get_billing_postcode(),
'billing_full_name' => $order->get_formatted_billing_full_name(),
'billing_email' => $order->get_billing_email()
);
$objPHPExcel->getProperties()->setCreator("RICOH")
->setLastModifiedBy("Ricoh Dash")
->setTitle("Order Procurement Report")
->setSubject("Order Procurement Report")
->setDescription("Order Procurement Report")
->setKeywords("office 2007 openxml php order procurement")
->setCategory("Procurement report file");
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Customer details')
->setCellValue('A2', 'Name')
->setCellValue('A3', 'Invoice address')
->setCellValue('A4', 'Invoice full name')
->setCellValue('A5', 'Invoice email')
->setCellValue('A6', 'VAT Number')
->setCellValue('B2', $info['customer_name'])
->setCellValue('B3', $info['billing_address'])
->setCellValue('B4', $info['billing_full_name'])
->setCellValue('B5', $info['billing_email'])
->setCellValue('B6', $info['vat_code']);
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A9', 'OrderDetails')
->setCellValue('A10', 'Order number')
->setCellValue('A11', 'Project number')
->setCellValue('A12', 'Delivery address')
->setCellValue('A13', 'Delivery full name')
->setCellValue('A14', 'Reference')
->setCellValue('B10', $info['number'])
->setCellValue('B11', $info['project_number'])
->setCellValue('B12', $info['delivery_address'])
->setCellValue('B13', $info['delivery_full_name'])
->setCellValue('B14', $info['reference']);
$objPHPExcel->getActiveSheet()->getStyle('A10')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->setTitle('Order procurement');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
header('Content-Disposition: attachment;filename="procurement_report_'.$info['orderNumber'].'.xlsx"');
$objWriter->save('php://output');
}
}
Wiaas_Procurement_Order::init();