示例#1
3
 function export_order($id)
 {
     global $FANNIE_OP_DB, $FANNIE_ROOT;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $order = new PurchaseOrderModel($dbc);
     $order->orderID($id);
     $order->load();
     $items = new PurchaseOrderItemsModel($dbc);
     $items->orderID($id);
     $vendor = new VendorsModel($dbc);
     $vendor->vendorID($order->vendorID());
     $vendor->load();
     $contact = new VendorContactModel($dbc);
     $contact->vendorID($order->vendorID());
     $contact->load();
     if (!class_exists('FPDF')) {
         include_once $FANNIE_ROOT . 'src/fpdf/fpdf.php';
     }
     $pdf = new FPDF('P', 'mm', 'Letter');
     $pdf->AddPage();
     $pdf->SetFont('Arial', '', '12');
     $pdf->Cell(100, 5, 'Vendor: ' . $vendor->vendorName(), 0, 0);
     $pdf->Cell(100, 5, 'Date: ' . date('Y-m-d'), 0, 0);
     $pdf->Ln();
     $pdf->Cell(100, 5, 'Phone: ' . $contact->phone(), 0, 0);
     $pdf->Cell(100, 5, 'Fax: ' . $contact->fax(), 0, 0);
     $pdf->Ln();
     $pdf->Cell(100, 5, 'Email: ' . $contact->email(), 0, 0);
     $pdf->Cell(100, 5, 'Website: ' . $contact->website(), 0, 0);
     $pdf->Ln();
     $pdf->MultiCell(0, 5, "Ordering Info:\n" . $contact->notes(), 'B');
     $pdf->Ln();
     $cur_page = 0;
     $pdf->SetFontSize(10);
     foreach ($items->find() as $obj) {
         if ($cur_page != $pdf->PageNo()) {
             $cur_page = $pdf->PageNo();
             $pdf->Cell(25, 5, 'SKU', 0, 0);
             $pdf->Cell(20, 5, 'Order Qty', 0, 0);
             $pdf->Cell(30, 5, 'Brand', 0, 0);
             $pdf->Cell(65, 5, 'Description', 0, 0);
             $pdf->Cell(20, 5, 'Case Size', 0, 0);
             $pdf->Cell(20, 5, 'Est. Cost', 0, 0);
             $pdf->Ln();
         }
         $pdf->Cell(25, 5, $obj->sku(), 0, 0);
         $pdf->Cell(20, 5, $obj->quantity(), 0, 0, 'C');
         $pdf->Cell(30, 5, $obj->brand(), 0, 0);
         $pdf->Cell(65, 5, $obj->description(), 0, 0);
         $pdf->Cell(20, 5, $obj->caseSize(), 0, 0, 'C');
         $pdf->Cell(20, 5, sprintf('%.2f', $obj->caseSize() * $obj->unitCost() * $obj->quantity()), 0, 0);
         $pdf->Ln();
     }
     $pdf->Output('order_export.pdf', 'D');
 }
示例#2
0
 function ajax_callbacks($action)
 {
     global $FANNIE_OP_DB;
     switch ($action) {
         case 'vendorDisplay':
             $this->getVendorInfo(FormLib::get_form_value('vid', 0));
             break;
         case 'newVendor':
             $this->newVendor(FormLib::get_form_value('name', ''));
             break;
         case 'saveDelivery':
             $delivery = new VendorDeliveriesModel(FannieDB::get($FANNIE_OP_DB));
             $delivery->vendorID(FormLib::get('vID', 0));
             $delivery->frequency(FormLib::get('frequency', 'weekly'));
             $delivery->regular(FormLib::get('regular') ? 1 : 0);
             $delivery->sunday(FormLib::get('sunday') ? 1 : 0);
             $delivery->monday(FormLib::get('monday') ? 1 : 0);
             $delivery->tuesday(FormLib::get('tuesday') ? 1 : 0);
             $delivery->wednesday(FormLib::get('wednesday') ? 1 : 0);
             $delivery->thursday(FormLib::get('thursday') ? 1 : 0);
             $delivery->friday(FormLib::get('friday') ? 1 : 0);
             $delivery->saturday(FormLib::get('saturday') ? 1 : 0);
             $ret = array();
             if ($delivery->regular()) {
                 $delivery->autoNext();
                 $ts1 = strtotime($delivery->nextDelivery());
                 $ts2 = strtotime($delivery->nextNextDelivery());
                 if ($ts1 !== false && $ts2 !== false) {
                     $ret['next'] = date('D, M jS', $ts1);
                     $ret['nextNext'] = date('D, M jS', $ts2);
                 }
             }
             $delivery->save();
             echo json_encode($ret);
             break;
         case 'saveContactInfo':
             $id = FormLib::get_form_value('vendorID', '');
             if ($id === '') {
                 echo 'Bad request';
                 break;
             }
             $web = FormLib::get_form_value('website');
             if (!empty($web) && substr(strtolower($web), 0, 4) !== "http") {
                 $web = 'http://' . $web;
             }
             $localID = FormLib::get_form_value('local-origin-id', 0);
             /** 29Oct2014 Andy
                     Widen vendors table so additional vendorContacts
                     table can be deprecated in the future
                 */
             $dbc = FannieDB::get($FANNIE_OP_DB);
             $vModel = new VendorsModel($dbc);
             $vModel->vendorID($id);
             $vModel->phone(FormLib::get_form_value('phone'));
             $vModel->fax(FormLib::get_form_value('fax'));
             $vModel->email(FormLib::get_form_value('email'));
             $vModel->website($web);
             $vModel->notes(FormLib::get_form_value('notes'));
             $vModel->localOriginID($localID);
             $success = $vModel->save();
             $vcModel = new VendorContactModel($dbc);
             $vcModel->vendorID($id);
             $vcModel->phone(FormLib::get_form_value('phone'));
             $vcModel->fax(FormLib::get_form_value('fax'));
             $vcModel->email(FormLib::get_form_value('email'));
             $vcModel->website($web);
             $vcModel->notes(FormLib::get_form_value('notes'));
             $success = $vcModel->save();
             $ret = array('error' => 0, 'msg' => '');
             if ($success) {
                 $ret['msg'] = 'Saved vendor information';
             } else {
                 $ret['msg'] = 'Error saving vendor information';
                 $ret['error'] = 1;
             }
             echo json_encode($ret);
             break;
         case 'saveShipping':
             $id = FormLib::get('id', '');
             $ret = array('error' => 0);
             if ($id === '') {
                 $ret['error'] = 'Bad request';
             } else {
                 $dbc = FannieDB::get($FANNIE_OP_DB);
                 $vModel = new VendorsModel($dbc);
                 $vModel->vendorID($id);
                 $vModel->shippingMarkup(FormLib::get('shipping') / 100.0);
                 if (!$vModel->save()) {
                     $ret['error'] = 'Save failed!';
                 }
             }
             echo json_encode($ret);
             break;
         case 'saveDiscountRate':
             $id = FormLib::get('id', '');
             $ret = array('error' => 0);
             if ($id === '') {
                 $ret['error'] = 'Bad request';
             } else {
                 $dbc = $this->connection;
                 $dbc->setDefaultDB($this->config->OP_DB);
                 $vModel = new VendorsModel($dbc);
                 $vModel->vendorID($id);
                 $vModel->discountRate(FormLib::get('rate') / 100.0);
                 if (!$vModel->save()) {
                     $ret['error'] = 'Save failed!';
                 }
             }
             echo json_encode($ret);
             break;
         default:
             echo 'Bad request';
             break;
     }
 }