Example #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');
 }
Example #2
0
 function export_order($id)
 {
     global $FANNIE_OP_DB;
     $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();
     echo 'Vendor,"' . $vendor->vendorName() . '",Order Date,' . date('Y-m-d') . "\r\n";
     echo "\r\n";
     echo "SKU,\"Order Qty\",Brand,Description,\"Case Size\",\"Est. Cost\"\r\n";
     foreach ($items->find() as $obj) {
         echo $obj->sku() . ',';
         echo $obj->quantity() . ',';
         echo '"' . $obj->brand() . '",';
         echo '"' . $obj->description() . '",';
         echo '"' . $obj->caseSize() . '",';
         printf('%.2f', $obj->unitCost() * $obj->caseSize() * $obj->quantity());
         echo "\r\n";
     }
 }
    /**
      overriding the basic form since I need several extra fields   
    */
    protected function basicForm()
    {
        global $FANNIE_OP_DB, $FANNIE_URL;
        $dbc = FannieDB::get($FANNIE_OP_DB);
        $vendors = new VendorsModel($dbc);
        ob_start();
        ?>
        <form enctype="multipart/form-data" class="form-horizontal" action="<?php 
        echo $_SERVER['PHP_SELF'];
        ?>
" id="FannieUploadForm" method="post">
        <div class="form-group col-sm-6">
            <label class="control-label col-sm-3">Vendor</label>
            <div class="col-sm-9"><select name=vendorID class="form-control">
            <?php 
        foreach ($vendors->find('vendorName') as $v) {
            printf("<option %s value=%d>%s</option>", $v->vendorName() == 'SPARTAN NASH' ? 'selected' : '', $v->vendorID(), $v->vendorName());
        }
        ?>
                </select></div>
        </div>
        <div class="form-group col-sm-6">
            <label class="control-label col-sm-3">Order Date</label>
            <div class="col-sm-9"><input type="text" class="form-control date-field" name="orderDate" id="orderDate" /></div>
        </div>
        <div class="form-group col-sm-6">
            <label class="control-label col-sm-3">PO#/Invoice#</label>
            <div class="col-sm-9"><input type="text" class="form-control" name="identifier" /></div>
        </div>
        <div class="form-group col-sm-6">
            <label class="control-label col-sm-3">Recv'd Date</label>
            <div class="col-sm-9"><input type="text" class="form-control date-field" name="recvDate" id="recvDate" /></div>
        </div>
        <div class="form-group col-sm-6">
            <label class="control-label col-sm-3">Filename</label>
            <div class="col-sm-9"><input type="file" class="form-control" name="FannieUploadFile" id="FannieUploadFile" /></div>
        </div>
        <div class="form-group col-sm-6">
            <button type="submit" class="btn btn-default">Upload File</button>
            <button type="button" class="btn btn-default" 
                onclick="location='PurchasingIndexPage.php'; return false;">Home</button>
        </div>
        <?php 
        return ob_get_clean();
    }
Example #4
0
    $vol_qtty = 0;
}
$descript = str_replace("'", "", $descript);
$descript = str_replace("\"", "", $descript);
$descript = $sql->escape($descript);
if (empty($manufacturer)) {
    $manufacturer = '';
}
if (empty($distributor)) {
    $distributor = '';
}
$manufacturer = str_replace("'", "", $manufacturer);
$distributor = str_replace("'", "", $distributor);
// lookup vendorID by name
$vendorID = 0;
$vendor = new VendorsModel($sql);
$vendor->vendorName($distributor);
foreach ($vendor->find('vendorID') as $obj) {
    $vendorID = $obj->vendorID();
    break;
}
$stamp = date("Y-m-d H:i:s");
$model = new ProductsModel($sql);
$model->upc($upc);
$model->description($descript);
$model->brand($manufacturer);
$model->normal_price($price);
$model->tax($tax);
$model->scale($Scale);
$model->foodstamp($FS);
$model->department($dept);
Example #5
0
 function post_u_view()
 {
     global $FANNIE_OP_DB, $FANNIE_URL;
     $this->addScript('from-search.js');
     $ret = '<form action="BatchFromSearch.php" method="post">';
     $ret .= '<div class="form-group form-inline">';
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $types = $dbc->query('SELECT batchTypeID, typeDesc, discType FROM batchType');
     $discTypes = array();
     $ret .= '<select name="batchType" id="batchType" class="form-control"
         onchange="discountTypeFixup()">';
     while ($row = $dbc->fetch_row($types)) {
         $ret .= sprintf('<option value="%d">%s</option>', $row['batchTypeID'], $row['typeDesc']);
         $discTypes[] = $row;
     }
     $ret .= '</select>';
     foreach ($discTypes as $row) {
         $ret .= sprintf('<input type="hidden" id="discType%d" value="%d" />', $row['batchTypeID'], $row['discType']);
     }
     $name = FannieAuth::checkLogin();
     $ret .= '
             <label>Name</label>: ';
     $ret .= '<input type="text" class="form-control" name="batchName" value="' . ($name ? $name : 'Batch') . ' ' . date('M j') . '" />';
     $ret .= '
             <label>Start</label>: <input type="text" class="form-control date-field" id="startDate" value="' . date('Y-m-d') . '" name="startDate" />
             ';
     $ret .= '
             <label>End</label>: <input type="text" class="form-control date-field" id="endDate" value="' . date('Y-m-d') . '" name="endDate" />
             </div>';
     $owners = $dbc->query('SELECT super_name FROM MasterSuperDepts GROUP BY super_name ORDER BY super_name');
     $ret .= '<div class="form-group form-inline">
         <label>Owner</label>: <select name="batchOwner" class="form-control" id="batchOwner"><option value=""></option>';
     while ($row = $dbc->fetch_row($owners)) {
         $ret .= '<option>' . $row['super_name'] . '</option>';
     }
     $ret .= '<option>IT</option></select>
             <button type="submit" name="createBatch" value="1"
                 class="btn btn-default">Create Batch</button>
             </div>';
     $ret .= '<hr />';
     list($in_sql, $args) = $dbc->safeInClause($this->upcs);
     $query = 'SELECT p.upc, p.description, p.normal_price, m.superID,
             MAX(CASE WHEN v.srp IS NULL THEN 0.00 ELSE v.srp END) as srp
             FROM products AS p
                 LEFT JOIN vendorItems AS v ON p.upc=v.upc AND p.default_vendor_id=v.vendorID
                 LEFT JOIN MasterSuperDepts AS m ON p.department=m.dept_ID
             WHERE p.upc IN ( ' . $in_sql . ')
             GROUP BY p.upc, p.description, p.normal_price, m.superID
             ORDER BY p.upc';
     $prep = $dbc->prepare($query);
     $result = $dbc->execute($prep, $args);
     $ret .= '<div id="saleTools" class="form-group form-inline">';
     $ret .= '<label>Markdown</label>
             <div class="input-group">
                 <input type="text" id="mdPercent" class="form-control" value="10" onchange="markDown(this.value);" />
                 <span class="input-group-addon">%</span>
             </div>
             <button type="submit" class="btn btn-default" onclick="markDown($(\'#mdPercent\').val()); return false">Go</button>';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<label>or</label>
             <div class="input-group">
                 <span class="input-group-addon">$</span>
                 <input type="text" id="mdDollar" class="form-control" value="0.00" onchange="discount(this.value);" />
             </div>
             <button type="submit" class="btn btn-default" onclick="discount($(\'#mdDollar\').val()); return false">Go</button>';
     $ret .= '</div>';
     $ret .= '<div id="priceChangeTools" class="form-group form-inline">';
     $ret .= '<button type="submit" class="btn btn-default" onclick="useSRPs(); return false;">Use Vendor SRPs</button>';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<select name="preferredVendor" class="form-control" onchange="reCalcSRPs();">
         <option value="0">Auto Choose Vendor</option>';
     $vendors = new VendorsModel($dbc);
     foreach ($vendors->find('vendorName') as $vendor) {
         $ret .= sprintf('<option value="%d">%s</option>', $vendor->vendorID(), $vendor->vendorName());
     }
     $ret .= '</select>';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<label>Markup</label>
             <div class="input-group">
                 <input type="text" id="muPercent" class="form-control" value="10" onchange="markUp(this.value);" />
                 <span class="input-group-addon">%</span>
             </div>
             <button type="submit" class="btn btn-default" onclick="markUp($(\'#muPercent\').val()); return false">Go</button>';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<label>Tags</label> <select name="tagset" class="form-control" id="tagset"><option value="">No Tags</option>';
     $queues = new ShelfTagQueuesModel($dbc);
     $ret .= $queues->toOptions();
     $ret .= '</select>';
     $ret .= '</div>';
     $ret .= '<table class="table">';
     $ret .= '<tr><th>UPC</th><th>Description</th><th>Retail</th>
             <th id="newPriceHeader">Sale Price</th></tr>';
     $superDetect = array();
     while ($row = $dbc->fetch_row($result)) {
         $ret .= sprintf('<tr class="batchItem">
                         <td><input type="hidden" name="upc[]" class="itemUPC" value="%s" />%s</td>
                         <td>%s</td>
                         <td>$%.2f<input type="hidden" class="currentPrice" value="%.2f" /></td>
                         <td><div class="input-group">
                             <span class="input-group-addon">$</span>
                             <input type="text" name="price[]" class="itemPrice form-control" value="0.00" />
                             <input type="hidden" class="itemSRP" value="%.2f" />
                         </div>
                         </td>
                         </tr>', $row['upc'], $row['upc'], $row['description'], $row['normal_price'], $row['normal_price'], $row['srp']);
         if (!isset($superDetect[$row['superID']])) {
             $superDetect[$row['superID']] = 0;
         }
         $superDetect[$row['superID']]++;
     }
     $ret .= '</table>';
     $ret .= '</form>';
     // auto-detect likely owner & tag set by super department
     $tagPage = array_search(max($superDetect), $superDetect);
     if ($tagPage !== false) {
         $this->add_onload_command("\$('#tagset').val({$tagPage});\n");
         $this->add_onload_command("\$('#batchOwner').val(\$('#tagset option:selected').text());\n");
     }
     // show sale or price change tools as appropriate
     $this->add_onload_command('discountTypeFixup();');
     // don't let enter key on these fields trigger form submission
     $this->add_onload_command("\$('#mdPercent').bind('keypress', noEnter);\n");
     $this->add_onload_command("\$('#mdDollar').bind('keypress', noEnter);\n");
     $this->add_onload_command("\$('#muPercent').bind('keypress', noEnter);\n");
     return $ret;
 }
Example #6
0
    function form_content()
    {
        global $FANNIE_OP_DB;
        $dbc = FannieDB::get($FANNIE_OP_DB);
        $deptQ = $dbc->prepare_statement("select dept_no,dept_name from departments order by dept_no");
        $deptR = $dbc->exec_statement($deptQ);
        $depts = array();
        while ($deptW = $dbc->fetch_array($deptR)) {
            $depts[$deptW['dept_no']] = $deptW['dept_name'];
        }
        $superQ = $dbc->prepare_statement("SELECT superID,super_name FROM superDeptNames \n            ORDER BY superID");
        $superR = $dbc->exec_statement($superQ);
        $supers = array();
        while ($superW = $dbc->fetch_row($superR)) {
            $supers[$superW['superID']] = $superW['super_name'];
        }
        $subs = array();
        if (count($depts) > 0) {
            $dept_numbers = array_keys($depts);
            $first = $dept_numbers[0];
            $subsP = $dbc->prepare('
                SELECT subdept_no,
                    subdept_name
                FROM subdepts
                WHERE dept_ID=?
                ORDER BY subdept_no');
            $subsR = $dbc->execute($subsP, array($first));
            while ($subsW = $dbc->fetch_row($subsR)) {
                $subs[$subsW['subdept_no']] = $subsW['subdept_name'];
            }
        }
        ob_start();
        ?>
        <form method="get" action="ProductListPage.php">
        <ul class="nav nav-tabs" role="tablist">
            <li class="active"><a href="#dept-tab" data-toggle="tab"
                onclick="$('#supertype').val('dept');">By Department</a></li>
            <li><a href="#manu-tab" data-toggle="tab"
                onclick="$('#supertype').val('manu');">By Brand</a></li>
            <li><a href="#vendor-tab" data-toggle="tab"
                onclick="$('#supertype').val('vendor');">By Vendor</a></li>
        </ul>
        <input id="supertype" name="supertype" type="hidden" value="dept" />
        <div class="tab-content">
            <p>
            <div class="tab-pane active" id="dept-tab">
                <div class="row form-horizontal">
                    <div class="col-sm-8">
                    <?php 
        echo FormLib::standardDepartmentFields('deptSub');
        ?>
                    </div>
                </div>
            </div>
            <div class="tab-pane" id="manu-tab">
                <div class="form-group form-inline">
                    <label><?php 
        echo _('Brand');
        ?>
</label>
                    <input type=text name=manufacturer class="form-control" />
                </div>
                <div class="form-group form-inline">
                    <label><input type=radio name=mtype value=prefix checked />
                        UPC prefix</label>
                    <label><input type=radio name=mtype value=name />
                        <?php 
        echo _('Brand name');
        ?>
</label>
                </div>
            </div>
            <div class="tab-pane" id="vendor-tab">
                <div class="form-group form-inline">
                    <label>Vendor</label>
                    <select name="vendor" class="form-control">
                    <?php 
        $vendors = new VendorsModel($dbc);
        foreach ($vendors->find('vendorName') as $v) {
            printf('<option value="%d">%s</option>', $v->vendorID(), $v->vendorName());
        }
        ?>
                    </select>
                </div>
            </div>
        </p>
        </div>
        <div class="form-group form-inline">
            <label>Sort by</label>
            <select name="sort" class="form-control">
                <option>Department</option>
                <option>UPC</option>
                <option>Description</option>
            </select> 
            <label>
                <input type=checkbox name="inUse" value="1" checked />
                In Use
            </label>
            |
            <label>
                <input type=checkbox name=excel />
                Excel
            </label>
        </div>
        <?php 
        if ($this->config->get('STORE_MODE') == 'HQ') {
            $picker = FormLib::storePicker();
            echo '<div class="form-group form-inline">
                <label>Store</label> ' . $picker['html'] . '</div>';
        }
        ?>
        <p> 
            <button type=submit name=submit class="btn btn-default btn-core">Submit</button>
            <button type=reset id="reset-btn" class="btn btn-default btn-reset"
                onclick="$('#super-id').val('').trigger('change');">Start Over</button>
        </p>
        </form>
        <?php 
        return ob_get_clean();
    }
Example #7
0
 private function newVendor($name)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $id = 1;
     $p = $dbc->prepare_statement("SELECT max(vendorID) FROM vendors");
     $rp = $dbc->exec_statement($p);
     $rw = $dbc->fetch_row($rp);
     if ($rw[0] != "") {
         $id = $rw[0] + 1;
     }
     $model = new VendorsModel($dbc);
     $model->vendorID($id);
     $model->vendorName($name);
     $model->vendorAbbreviation(substr($name, 0, 10));
     $model->save();
     echo $id;
 }
Example #8
0
 function post_save_handler()
 {
     global $FANNIE_OP_DB;
     $upcs = FormLib::get('upc', array());
     if (!is_array($upcs) || empty($upcs)) {
         echo 'Error: invalid data';
         return false;
     }
     $dept = FormLib::get('dept');
     $tax = FormLib::get('tax');
     $local = FormLib::get('local');
     $brand = FormLib::get('brand');
     $vendor = FormLib::get('vendor');
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $vlookup = new VendorsModel($dbc);
     for ($i = 0; $i < count($upcs); $i++) {
         $model = new ProductsModel($dbc);
         $upc = BarcodeLib::padUPC($upcs[$i]);
         $model->upc($upc);
         $model->store_id(1);
         if (isset($dept[$i])) {
             $model->department($dept[$i]);
         }
         if (isset($tax[$i])) {
             $model->tax($tax[$i]);
         }
         if (isset($local[$i])) {
             $model->local($local[$i]);
         }
         if (isset($brand[$i])) {
             $model->brand($brand[$i]);
         }
         if (isset($vendor[$i])) {
             $vlookup->reset();
             $vlookup->vendorName($vendor[$i]);
             foreach ($vlookup->find('vendorID') as $obj) {
                 $model->default_vendor_id($obj->vendorID());
                 break;
             }
         }
         if (in_array($upc, FormLib::get('fs', array()))) {
             $model->foodstamp(1);
         } else {
             $model->foodstamp(0);
         }
         if (in_array($upc, FormLib::get('disc', array()))) {
             $model->discount(1);
         } else {
             $model->discount(0);
         }
         if (in_array($upc, FormLib::get('scale', array()))) {
             $model->scale(1);
         } else {
             $model->scale(0);
         }
         $model->modified(date('Y-m-d H:i:s'));
         $try = $model->save();
         if ($try) {
             $model->pushToLanes();
         } else {
             $this->save_results[] = 'Error saving item ' . $upc;
         }
         if (isset($vendor[$i]) && $vendor[$i] != '' || isset($brand[$i]) && $brand[$i] != '') {
             $extra = new ProdExtraModel($dbc);
             $extra->upc($upc);
             if (isset($vendor[$i]) && $vendor[$i] != '') {
                 $extra->distributor($vendor[$i]);
             }
             if (isset($brand[$i]) && $brand[$i] != '') {
                 $extra->manufacturer($brand[$i]);
             }
             $extra->save();
         }
         $this->upcs[] = $upc;
     }
     return true;
 }
Example #9
0
 public function preprocess()
 {
     global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB, $FANNIE_URL, $FANNIE_TRANS_DB;
     //$this->add_script($FANNIE_URL.'src/javascript/jquery.js');
     //$this->add_script($FANNIE_URL.'src/javascript/jquery-ui.js');
     if (FormLib::get('upc_in') !== '') {
         $upc = BarcodeLib::padUPC(FormLib::get('upc_in'));
         $this->current_item_data['upc'] = $upc;
         $dbc = FannieDB::get($FANNIE_OP_DB);
         $model = new ProductsModel($dbc);
         $model->upc($upc);
         $vendorID = 0;
         if ($model->load()) {
             $this->current_item_data['desc'] = $model->brand() . ' ' . $model->description();
             $this->current_item_data['par'] = $model->auto_par();
             $vendorID = $model->default_vendor_id();
         }
         $model = new VendorsModel($dbc);
         $model->vendorID($vendorID);
         if ($model->load()) {
             $this->current_item_data['vendor'] = $model->vendorName();
             $schedule = new VendorDeliveriesModel($dbc);
             $schedule->vendorID($vendorID);
             if ($schedule->load() && $schedule->regular() == 1) {
                 $this->current_item_data['nextDelivery'] = date('D, M jS', strtotime($schedule->nextDelivery())) . ' & ' . date('D, M jS', strtotime($schedule->nextNextDelivery()));
                 $nd = new DateTime(date('Y-m-d', strtotime($schedule->nextDelivery())));
                 $nnd = new DateTime(date('Y-m-d', strtotime($schedule->nextNextDelivery())));
                 $this->current_item_data['deliverySpan'] = $nnd->diff($nd)->format('%a');
             }
             $items = new VendorItemsModel($dbc);
             $items->vendorID($vendorID);
             $items->upc($upc);
             $this->current_item_data['cases'] = array();
             foreach ($items->find('units') as $item) {
                 $this->current_item_data['cases'][] = $item->units();
             }
         }
         $saleNow = 'SELECT b.batchName, b.startDate, b.endDate
                     FROM batchList AS l
                         INNER JOIN batches AS b ON b.batchID=l.batchID
                     WHERE l.upc=?
                         AND b.discounttype <> 0
                         AND b.startDate <= ' . $dbc->now() . '
                         AND b.endDate >= ' . $dbc->now();
         $saleNow = $dbc->prepare($saleNow);
         $saleNow = $dbc->execute($saleNow, array($upc));
         if ($dbc->num_rows($saleNow) > 0) {
             $row = $dbc->fetch_row($saleNow);
             $this->current_item_data['onSale'] = $row['batchName'] . ' thru ' . date('D, M jS', strtotime($row['endDate']));
         }
         $saleNext = 'SELECT b.batchName, b.startDate, b.endDate
                     FROM batchList AS l
                         INNER JOIN batches AS b ON b.batchID=l.batchID
                     WHERE l.upc=?
                         AND b.discounttype <> 0
                         AND b.startDate >= ' . $dbc->now() . '
                         AND b.endDate >= ' . $dbc->now();
         $saleNext = $dbc->prepare($saleNext);
         $saleNext = $dbc->execute($saleNext, array($upc));
         if ($dbc->num_rows($saleNext) > 0) {
             $row = $dbc->fetch_row($saleNext);
             $this->current_item_data['soonSale'] = $row['batchName'] . ' on ' . date('D, M jS', strtotime($row['startDate']));
         }
         $ordersQ = 'SELECT v.vendorName,
                         o.placedDate,
                         i.quantity,
                         i.caseSize
                     FROM PurchaseOrderItems AS i
                         INNER JOIN PurchaseOrder AS o ON i.orderID=o.orderID
                         INNER JOIN vendors AS v ON o.vendorID=v.vendorID
                     WHERE i.internalUPC = ?
                     ORDER BY o.placedDate DESC';
         $ordersQ = $dbc->add_select_limit($ordersQ, 10);
         $ordersP = $dbc->prepare($ordersQ);
         $ordersR = $dbc->execute($ordersP, array($upc));
         $orders = array();
         while ($w = $dbc->fetch_row($ordersR)) {
             $orders[] = $w;
         }
         $this->current_item_data['orders'] = $orders;
         $salesQ = 'SELECT ' . DTrans::sumQuantity('d') . ' AS qty,
                     MIN(tdate) as day
                    FROM ' . $FANNIE_TRANS_DB . $dbc->sep() . 'dlog_15 AS d
                    WHERE upc = ?
                    GROUP BY YEAR(tdate), MONTH(tdate), DAY(tdate)
                    ORDER BY YEAR(tdate) DESC, MONTH(tdate) DESC, DAY(tdate) DESC';
         $salesP = $dbc->prepare($salesQ);
         $salesR = $dbc->execute($salesP, array($upc));
         $sales = array();
         while ($w = $dbc->fetch_row($salesR)) {
             $sales[] = $w;
         }
         $this->current_item_data['sales'] = $sales;
     }
     $this->linea_ios_mode = $this->linea_support_available();
     if ($this->linea_ios_mode) {
         $this->add_script($FANNIE_URL . 'src/javascript/linea/cordova-2.2.0.js');
         $this->add_script($FANNIE_URL . 'src/javascript/linea/ScannerLib-Linea-2.0.0.js');
     }
     $this->add_script($FANNIE_URL . 'src/javascript/tablesorter/jquery.tablesorter.js');
     $this->add_css_file($FANNIE_URL . 'src/javascript/tablesorter/themes/blue/style.css');
     //$this->add_css_file($FANNIE_URL.'src/javascript/jquery-ui.css');
     return true;
 }
Example #10
0
 public function get_view()
 {
     $dbc = FannieDB::get($this->config->get('OP_DB'));
     $ret = '<form action="' . $_SERVER['PHP_SELF'] . '" method="get">
         <div class="form-group">
             <label>Vendor</label>
             <select name="id" class="form-control">';
     $vendors = new VendorsModel($dbc);
     foreach ($vendors->find('vendorName') as $obj) {
         $ret .= sprintf('<option value="%d">%s</option>', $obj->vendorID(), $obj->vendorName());
     }
     $ret .= '</select>
         </div>
         <div class="form-group">
             <button type="submit" class="btn btn-default">Continue</button>
         </div>';
     return $ret;
 }
Example #11
0
 public function post_file_view()
 {
     $invoice_num = false;
     $invoice_date = false;
     $po_num = false;
     $items = array();
     $lines = explode("\n", $this->file_content);
     $pattern = '/\\d+\\s+(\\d+)\\s+[^0-9]*(\\d\\d\\d+)\\s+(.*?)\\s\\s+(.*?)\\s+([0-9-]+)\\s+\\d+\\s+\\$?([0-9\\.]+)\\s+\\$?([0-9\\.]+)\\s+\\$?([0-9\\.]+)/';
     echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">';
     echo '<table class="table">';
     echo '<tr><thead>
         <th>SKU</th>
         <th>UPC</th>
         <th>Description</th>
         <th>Total Cost</th>
         <th># Cases</th>
         <th>Units/Case</th>
         <th>Unit Size</th>
         <th>Unit Cost</th>
         </tr>
         </thead>';
     for ($i = 0; $i < count($lines); $i++) {
         $line = trim($lines[$i]);
         $fields = preg_split('/\\s{2,}/', $line);
         if (count($fields) == 0) {
             continue;
         }
         if ($i == 1 && count($fields) >= 6) {
             $invoice_num = $fields[2];
             $po_num = $fields[3];
             $invoice_date = $fields[5];
         } else {
             if (!preg_match($pattern, $line, $matches)) {
                 /**
                   Excessively wide fields can break the layout and split the single PDF line
                   into two text lines. Try joining consecutive lines and see if they
                   match the single-line pattern
                 */
                 if ($i + 1 < count($lines) && preg_match($pattern, $line . ' ' . $lines[$i + 1], $matches)) {
                     $i++;
                 } else {
                     continue;
                 }
             }
             $numCases = $matches[1];
             $sku = $matches[2];
             $description = $matches[3];
             list($caseSize, $unitSize) = $this->caseAndUnit($description);
             $upc = $matches[5];
             if (strlen($upc) == 5 && $upc[0] == '9') {
                 $upc = substr($upc, 1);
             } elseif (strstr($upc, '-')) {
                 $upc = substr($upc, 0, strlen($upc) - 1);
             }
             $upc = str_replace('-', '', $upc);
             $upc = BarcodeLib::padUPC($upc);
             $receivedCost = $matches[7];
             printf('<tr>
                 <td><input type="number" class="form-control input-sm" name="sku[]" value="%s" /></td>
                 <td><input type="number" class="form-control input-sm" name="upc[]" value="%s" /></td>
                 <td><input type="text" class="form-control input-sm" name="description[]" value="%s" /></td>
                 <td>
                     <div class="input-group">
                         <span class="input-group-addon">$</span>
                         <input type="text" class="form-control input-sm" name="total[]" value="%.2f" />
                     </div>
                 </td>
                 <td><input type="number" class="form-control input-sm" name="cases[]" value="%s" /></td>
                 <td><input type="text" class="form-control input-sm" name="units[]" value="%s" /></td>
                 <td><input type="text" class="form-control input-sm" name="size[]" value="%s" /></td>
                 <td>
                     <div class="input-group">
                         <span class="input-group-addon">$</span>
                         <input type="text" class="form-control input-sm" name="cost[]" value="%.2f" />
                     </div>
                 </td>
                 </tr>', $sku, $upc, $description, $receivedCost, $numCases, $caseSize, $unitSize, $receivedCost / $numCases / $caseSize);
         }
     }
     echo '</table>';
     printf('<div class="form-group">
         <label>Invoice #</label>
         <input type="text" name="invoice_num" value="%s" class="form-control" />
         </div>', $invoice_num);
     printf('<div class="form-group">
         <label>PO #</label>
         <input type="text" name="po_num" class="form-control" value="%s" />
         </div>', $po_num);
     printf('<div class="form-group">
         <label>Invoice Date</label>
         <input type="text" class="form-control date-field" name="invoice_date" value="%s" />
         </div>', $invoice_date);
     $dbc = FannieDB::get($this->config->get('OP_DB'));
     $vendors = new VendorsModel($dbc);
     echo '<div class="form-group">
         <label>Vendor</label>
         <select class="form-control" name="vendorID">';
     foreach ($vendors->find('vendorName') as $obj) {
         printf('<option %s value="%d">%s</option>', preg_match('/albert/i', $obj->vendorName()) ? 'selected' : '', $obj->vendorID(), $obj->vendorName());
     }
     echo '</select></div>';
     echo '<p>
         <button type="submit" class="btn btn-default">Import Invoice</button>
         </p>';
     echo '</form>';
 }
Example #12
0
 function AjaxCallback()
 {
     $db = $this->db();
     $json = array();
     if (FormLib::get('action') == 'addVendor') {
         $name = FormLib::get('newVendorName');
         if (empty($name)) {
             $json['error'] = 'Name is required';
         } else {
             $vendor = new VendorsModel($db);
             $vendor->vendorName($name);
             if (count($vendor->find()) > 0) {
                 $json['error'] = 'Vendor "' . $name . '" already exists';
             } else {
                 $max = $db->query('SELECT MAX(vendorID) AS max
                                    FROM vendors');
                 $newID = 1;
                 if ($max && ($maxW = $db->fetch_row($max))) {
                     $newID = (int) $maxW['max'] + 1;
                 }
                 $vendor->vendorAbbreviation(substr($name, 0, 10));
                 $vendor->vendorID($newID);
                 $vendor->save();
                 $json['vendorID'] = $newID;
                 $json['vendorName'] = $name;
             }
         }
     } elseif (FormLib::get('dept_defaults') !== '') {
         $json = array('tax' => 0, 'fs' => False, 'nodisc' => False);
         $dept = FormLib::get_form_value('dept_defaults', '');
         $p = $db->prepare_statement('SELECT dept_tax,dept_fs,dept_discount
                 FROM departments WHERE dept_no=?');
         $r = $db->exec_statement($p, array($dept));
         if ($db->num_rows($r)) {
             $w = $db->fetch_row($r);
             $json['tax'] = $w['dept_tax'];
             if ($w['dept_fs'] == 1) {
                 $json['fs'] = True;
             }
             if ($w['dept_discount'] == 0) {
                 $json['nodisc'] = True;
             }
         }
     } elseif (FormLib::get('vendorChanged') !== '') {
         $v = new VendorsModel($db);
         $v->vendorName(FormLib::get('vendorChanged'));
         $matches = $v->find();
         $json = array('error' => false);
         if (count($matches) == 1) {
             $json['localID'] = $matches[0]->localOriginID();
             $json['vendorID'] = $matches[0]->vendorID();
         } else {
             $json['error'] = true;
         }
     }
     echo json_encode($json);
 }
Example #13
0
 function get_id_view()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $order = new PurchaseOrderModel($dbc);
     $order->orderID($this->id);
     $order->load();
     $vendor = new VendorsModel($dbc);
     $vendor->vendorID($order->vendorID());
     $vendor->load();
     $ret = '<p><div class="form-inline">';
     $ret .= '<b>Vendor</b>: ' . $vendor->vendorName();
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<b>Created</b>: ' . $order->creationDate();
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<b>Placed</b>: <span id="orderPlacedSpan">' . ($order->placed() ? $order->placedDate() : 'n/a') . '</span>';
     $ret .= '<input type="checkbox" ' . ($order->placed() ? 'checked' : '') . ' id="placedCheckbox"
             onclick="togglePlaced(' . $this->id . ');" />';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= 'Export as: <select id="exporterSelect" class="form-control">';
     $dh = opendir('exporters');
     while (($file = readdir($dh)) !== False) {
         if (substr($file, -4) != '.php') {
             continue;
         }
         include 'exporters/' . $file;
         $class = substr($file, 0, strlen($file) - 4);
         if (!class_exists($class)) {
             continue;
         }
         $obj = new $class();
         if (!isset($obj->nice_name)) {
             continue;
         }
         $ret .= '<option value="' . $class . '">' . $obj->nice_name . '</option>';
     }
     $ret .= '</select> ';
     $ret .= '<button type="submit" class="btn btn-default" onclick="doExport(' . $this->id . ');return false;">Export</button>';
     $ret .= '&nbsp;&nbsp;&nbsp;';
     $init = $order->placed() ? 'init=placed' : 'init=pending';
     $ret .= '<button type="button" class="btn btn-default" 
         onclick="location=\'ViewPurchaseOrders.php?' . $init . '\'; return false;">All Orders</button>';
     $ret .= '</div></p>';
     $ret .= '<div class="row"><div class="col-sm-6">';
     $ret .= '<table class="table table-bordered"><tr><th colspan="2">Coding(s)</th>';
     $ret .= '<td><b>PO#</b>: ' . $order->vendorOrderID() . '</td>';
     $ret .= '<td><b>Invoice#</b>: ' . $order->vendorInvoiceID() . '</td>';
     $ret .= '</tr>';
     $ret .= '{{CODING}}';
     $ret .= '</table>';
     $ret .= '</div><div class="col-sm-6">';
     if (!$order->placed()) {
         $ret .= '<button class="btn btn-default"
             onclick="location=\'EditOnePurchaseOrder.php?id=' . $order->vendorID() . '\'; return false;">Add Items</button>';
         $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
         $ret .= '<button class="btn btn-default" onclick="deleteOrder(' . $this->id . '); return false;">Delete Order</button>';
     } else {
         $ret .= '<a class="btn btn-default"
             href="ManualPurchaseOrderPage.php?id=' . $order->vendorID() . '&adjust=' . $this->id . '">Edit Order</a>';
         $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
         $ret .= '<a class="btn btn-default"
             href="ViewPurchaseOrders.php?id=' . $this->id . '&receive=1">Receive Order</a>';
         $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
         $ret .= '<a class="btn btn-default"
             href="ViewPurchaseOrders.php?id=' . $this->id . '&recode=1">Alter Codings</a>';
     }
     $ret .= '</div></div>';
     $model = new PurchaseOrderItemsModel($dbc);
     $model->orderID($this->id);
     $codings = array();
     $accounting = $this->config->get('ACCOUNTING_MODULE');
     if (!class_exists($accounting)) {
         $accounting = '\\COREPOS\\Fannie\\API\\item\\Accounting';
     }
     $ret .= '<table class="table tablesorter"><thead>';
     $ret .= '<tr><th>Coding</th><th>SKU</th><th>UPC</th><th>Brand</th><th>Description</th>
         <th>Unit Size</th><th>Units/Case</th><th>Cases</th>
         <th>Est. Cost</th><th>&nbsp;</th><th>Received</th>
         <th>Rec. Qty</th><th>Rec. Cost</th></tr></thead><tbody>';
     foreach ($model->find() as $obj) {
         $css = '';
         if ($obj->receivedQty() == 0 && $obj->quantity() != 0) {
             $css = 'class="danger"';
         } elseif ($obj->receivedQty() < $obj->quantity()) {
             $css = 'class="warning"';
         }
         if ($obj->salesCode() == '') {
             $code = $obj->guessCode();
             $obj->salesCode($code);
             $obj->save();
         }
         $coding = (int) $obj->salesCode();
         $coding = $accounting::toPurchaseCode($coding);
         if (!isset($codings[$coding])) {
             $codings[$coding] = 0.0;
         }
         $codings[$coding] += $obj->receivedTotalCost();
         $ret .= sprintf('<tr %s><td>%d</td><td>%s</td>
                 <td><a href="../item/ItemEditorPage.php?searchupc=%s">%s</a></td><td>%s</td><td>%s</td>
                 <td>%s</td><td>%s</td><td>%d</td><td>%.2f</td>
                 <td>&nbsp;</td><td>%s</td><td>%d</td><td>%.2f</td>
                 </tr>', $css, $accounting::toPurchaseCode($obj->salesCode()), $obj->sku(), $obj->internalUPC(), $obj->internalUPC(), $obj->brand(), $obj->description(), $obj->unitSize(), $obj->caseSize(), $obj->quantity(), $obj->quantity() * $obj->caseSize() * $obj->unitCost(), date('Y-m-d', strtotime($obj->receivedDate())), $obj->receivedQty(), $obj->receivedTotalCost());
     }
     $ret .= '</tbody></table>';
     $coding_rows = '';
     foreach ($codings as $coding => $ttl) {
         $coding_rows .= sprintf('<tr><td>%d</td><td>%.2f</td></tr>', $coding, $ttl);
     }
     $ret = str_replace('{{CODING}}', $coding_rows, $ret);
     $this->add_script('js/view.js');
     $this->add_script('../src/javascript/tablesorter/jquery.tablesorter.min.js');
     $this->addOnloadCommand("\$('.tablesorter').tablesorter();\n");
     return $ret;
 }
Example #14
0
 /**
   First page. Show vendor list.
 */
 function get_view()
 {
     global $FANNIE_OP_DB;
     $model = new VendorsModel(FannieDB::get($FANNIE_OP_DB));
     $ret = '';
     $ret .= '<form class="form" action="EditOnePurchaseOrder.php" method="get">';
     $ret .= '<div class="form-group">';
     $ret .= '<label>Select a vendor</label>';
     $ret .= '<select name="id" class="form-control">';
     foreach ($model->find('vendorName') as $vendor) {
         $ret .= sprintf('<option value="%d">%s</option>', $vendor->vendorID(), $vendor->vendorName());
     }
     $ret .= '</select>';
     $ret .= '</div>';
     $ret .= '<p><button type="submit" class="btn btn-default">Go</button>';
     $ret .= '&nbsp;&nbsp;&nbsp;';
     $ret .= '<button type="button" class="btn btn-default"
         onclick="location=\'PurchasingIndexPage.php\'; return false;">Home</button></p>';
     $ret .= '</form>';
     return $ret;
 }
Example #15
0
 public function post_file_view()
 {
     $inv_no = '';
     $inv_date = '';
     $po_no = '';
     $line = 0;
     for ($line; $line < count($this->filedata); $line++) {
         $data = $this->filedata[$line];
         if (isset($data[4]) && $data[4] == 'Invoice No:') {
             $inv_no = $data[6];
         } elseif (isset($data[4]) && $data[4] == 'PO #:') {
             $po_no = $data[6];
         } elseif (isset($data[4]) && $data[4] == 'Order Date:') {
             $inv_date = \COREPOS\Fannie\API\data\FileData::excelFloatToDate($data[6]);
         } elseif (in_array('Ordered', $data) && in_array('Price', $data)) {
             break;
             // item data begins
         }
     }
     $ret = '<form method="post">';
     $ret .= '<div class="form-group">
         <label>Invoice #</label>
         <input type="text" name="invoice_num" class="form-control" value="' . $inv_no . '" />
         </div>';
     $ret .= '<div class="form-group">
         <label>PO #</label>
         <input type="text" name="po_num" class="form-control" value="' . $po_no . '" />
         </div>';
     $ret .= '<div class="form-group">
         <label>Invoice Date</label>
         <input type="text" name="invoice_date" class="form-control date-field" value="' . $inv_date . '" />
         </div>';
     $dbc = FannieDB::get($this->config->get('OP_DB'));
     $vendors = new VendorsModel($dbc);
     $ret .= '<div class="form-group">
         <label>Vendor</label>
         <select class="form-control" name="vendorID">';
     $vendorID = 0;
     foreach ($vendors->find('vendorName') as $obj) {
         $ret .= sprintf('<option %s value="%d">%s</option>', preg_match('/cpw/i', $obj->vendorName()) ? 'selected' : '', $obj->vendorID(), $obj->vendorName());
         if (preg_match('/cpw/i', $obj->vendorName())) {
             $vendorID = $obj->vendorID();
         }
     }
     $ret .= '</select></div>';
     $ret .= '<table class="table">
         <tr>
             <th>SKU</th>
             <th>UPC</th>
             <th>Item</th>
             <th>Unit Size</th>
             <th>Case Size</th>
             <th># of Cases</th>
             <th>Unit Cost</th>
             <th>Total Cost</th>
         </tr>';
     $upcP = $dbc->prepare('
         SELECT upc
         FROM vendorItems
         WHERE vendorID=?
             AND sku=?');
     for ($line; $line < count($this->filedata); $line++) {
         $data = $this->filedata[$line];
         if (!is_numeric($data[0]) || !is_numeric($data[5]) || !is_numeric($data[7])) {
             // not an item line
             continue;
         }
         $numCases = $data[1];
         $description = $data[2];
         $sku = $data[5];
         $caseCost = $data[6];
         $totalCost = $data[7];
         list($caseSize, $unitSize) = $this->caseAndUnit($description);
         $unitCost = $caseCost / $caseSize;
         $upc = '';
         $upcR = $dbc->execute($upcP, array($vendorID, $sku));
         if ($upcR && $dbc->numRows($upcR)) {
             $upcW = $dbc->fetchRow($upcR);
             $upc = $upcW['upc'];
         }
         $ret .= sprintf('<tr>
             <td><input type="text" name="sku[]" size="8" value="%s" class="form-control input-sm" /></td>
             <td><input type="text" name="upc[]" size="13" value="%s" class="form-control upc-field input-sm" /></td>
             <td><input type="text" name="desc[]" value="%s" class="form-control input-sm" /></td>
             <td><input type="text" name="size[]" size="3" value="%s" class="form-control input-sm" /></td>
             <td><input type="text" name="units[]" size="4" value="%s" class="form-control input-sm" /></td>
             <td><input type="text" name="qty[]" size="3" value="%d" class="form-control input-sm" /></td>
             <td>
                 <div class="input-group">
                     <div class="input-group-addon">$</div>
                     <input type="text" name="unitCost[]" size="5" value="%.2f" class="form-control input-sm" />
                 </div>
             </td>
             <td>
                 <div class="input-group">
                     <div class="input-group-addon">$</div>
                     <input type="text" name="totalCost[]" size="5" value="%.2f" class="form-control input-sm" />
                 </div>
             </td>
             </tr>', $sku, $upc, $description, $unitSize, $caseSize, $numCases, $unitCost, $totalCost);
     }
     $ret .= '</table>
         <p>
             <button type="submit" class="btn btn-default">Import Invoice</button>
         </p>
         </form>';
     $this->addScript('../../item/autocomplete.js');
     $this->addOnloadCommand("bindAutoComplete('.upc-field', '../../ws/', 'item');\n");
     return $ret;
 }
Example #16
0
 private function vendorDeptDisplay($id)
 {
     global $FANNIE_OP_DB, $FANNIE_URL;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $v = new VendorsModel($dbc);
     $v->vendorID($id);
     $v->load();
     $name = $v->vendorName();
     $ret = "<strong>Subcategories in {$name}</strong><br />";
     $ret .= "<table class=\"table\">";
     $ret .= "<tr><th>No.</th><th>Name</th><th>Margin</th><th>POS Dept#</th>\n            <th>&nbsp;</th><th>&nbsp;</th></tr>";
     $deptQ = $dbc->prepare_statement("\n            SELECT d.vendorID,\n                deptID,\n                name,\n                margin,\n                testing,\n                posDeptID\n            FROM vendorDepartments AS d\n            WHERE d.vendorID=?\n            ORDER BY deptID");
     $deptR = $dbc->exec_statement($deptQ, array($id));
     while ($row = $dbc->fetch_row($deptR)) {
         $ret .= sprintf("<tr id=\"row-%d\">\n                <td>%d</td>\n                <td id=nametd%d>%s</td>\n                <td id=margintd%d>%.2f%%</td>\n                <td id=posdepttd%d>%d</td>\n                <td id=button%d>\n                    <a href=\"\" onclick=\"edit(%d);return false;\"\n                        class=\"edit-link\">%s</a>\n                    <a href=\"\" onclick=\"save(%d);return false;\"\n                        class=\"save-link collapse\">%s</a>\n                </td>\n                <td><a href=\"\" onclick=\"deleteCat(%d,'%s');return false\">%s</a></td>\n                <td><a href=\"../../reports/VendorCategory/VendorCategoryReport.php?id=%d&category=%d\"\n                    title=\"View Items in this Category\">\n                    <span class=\"glyphicon glyphicon-th-list\"></span>\n                    </a></td>\n                </tr>", $row['deptID'], $row['deptID'], $row['deptID'], $row['name'], $row['deptID'], $row['margin'] * 100, $row['deptID'], $row['posDeptID'], $row['deptID'], $row['deptID'], \COREPOS\Fannie\API\lib\FannieUI::editIcon(), $row['deptID'], \COREPOS\Fannie\API\lib\FannieUI::saveIcon(), $row['deptID'], $row['name'], \COREPOS\Fannie\API\lib\FannieUI::deleteIcon(), $id, $row['deptID']);
     }
     $ret .= "</table>";
     $ret .= '<p><a href="VendorIndexPage.php?vid=' . $id . '" class="btn btn-default">Home</a></p>';
     return $ret;
 }
Example #17
0
function addUPC($orderID, $memNum, $upc, $num_cases = 1)
{
    global $FANNIE_OP_DB, $TRANS;
    $dbc = FannieDB::get($FANNIE_OP_DB);
    $sku = str_pad($upc, 6, '0', STR_PAD_LEFT);
    if (is_numeric($upc)) {
        $upc = BarcodeLib::padUPC($upc);
    }
    $manualSKU = false;
    if (isset($upc[0]) && $upc[0] == "+") {
        $sku = substr($upc, 1);
        $upc = "zimbabwe";
        // string that will not match
        $manualSKU = true;
    }
    $ins_array = genericRow($orderID);
    $ins_array['upc'] = "{$upc}";
    if ($manualSKU) {
        $ins_array['upc'] = BarcodeLib::padUPC($sku);
    }
    $ins_array['card_no'] = "{$memNum}";
    $ins_array['trans_type'] = "I";
    $caseSize = 1;
    $vendor = "";
    $vendor_desc = !is_numeric($upc) ? $upc : "";
    $srp = 0.0;
    $vendor_upc = !is_numeric($upc) ? '0000000000000' : "";
    $skuMatch = 0;
    $caseP = $dbc->prepare_statement("\n        SELECT units,\n            vendorName,\n            description,\n            i.srp,\n            i.upc,\n            CASE WHEN i.upc=? THEN 0 ELSE 1 END as skuMatch \n        FROM vendorItems as i\n            LEFT JOIN vendors AS v ON i.vendorID=v.vendorID \n        WHERE i.upc=? \n            OR i.sku=? \n            OR i.sku=?\n        ORDER BY i.vendorID");
    $caseR = $dbc->exec_statement($caseP, array($upc, $upc, $sku, '0' . $sku));
    if ($dbc->num_rows($caseR) > 0) {
        $row = $dbc->fetch_row($caseR);
        $caseSize = $row['units'];
        $vendor = $row['vendorName'];
        $vendor_desc = $row['description'];
        $srp = $row['srp'];
        $vendor_upc = $row['upc'];
        $skuMatch = $row['skuMatch'];
    }
    if (!empty($vendor_upc)) {
        $ins_array['upc'] = "{$vendor_upc}";
    }
    if ($skuMatch == 1) {
        $ins_array['upc'] = "{$vendor_upc}";
        $upc = $vendor_upc;
    }
    $ins_array['quantity'] = $caseSize;
    $ins_array['ItemQtty'] = $num_cases;
    $ins_array['mixMatch'] = substr($vendor, 0, 26);
    $ins_array['description'] = substr($vendor_desc, 0, 32) . " SO";
    $mempricing = false;
    if ($memNum != 0 && !empty($memNum)) {
        $p = $dbc->prepare_statement("SELECT Type,memType FROM custdata WHERE CardNo=?");
        $r = $dbc->exec_statement($p, array($memNum));
        $w = $dbc->fetch_row($r);
        if ($w['Type'] == 'PC') {
            $mempricing = true;
        } elseif ($w['memType'] == 9) {
            $mempricing = true;
        }
    }
    $pdP = $dbc->prepare_statement("\n        SELECT normal_price,\n            special_price,\n            department,\n            discounttype,\n            description,\n            discount,\n            default_vendor_id\n        FROM products WHERE upc=?");
    $pdR = $dbc->exec_statement($pdP, array($upc));
    $qtyReq = False;
    if ($dbc->num_rows($pdR) > 0) {
        $pdW = $dbc->fetch_row($pdR);
        $ins_array['department'] = $pdW['department'];
        $ins_array['discountable'] = $pdW['discount'];
        $mapP = $dbc->prepare_statement("SELECT map_to FROM \n                {$TRANS}SpecialOrderDeptMap WHERE dept_ID=?");
        $mapR = $dbc->exec_statement($mapP, array($pdW['department']));
        if ($dbc->num_rows($mapR) > 0) {
            $ins_array['department'] = array_pop($dbc->fetch_row($mapR));
        }
        $superP = $dbc->prepare_statement("SELECT superID \n                FROM superdepts WHERE dept_ID=?");
        $superR = $dbc->exec_statement($superP, array($ins_array['department']));
        while ($superW = $dbc->fetch_row($superR)) {
            if ($superW[0] == 5) {
                $qtyReq = 3;
            }
            if ($qtyReq !== false) {
                $caseSize = $qtyReq;
                $ins_array['quantity'] = $qtyReq;
                break;
            }
        }
        // only calculate prices for items that exist in
        // vendorItems (i.e., have known case size)
        $ins_array['discounttype'] = $pdW['discounttype'];
        if ($dbc->num_rows($caseR) > 0 || true) {
            // test always do this
            $ins_array['total'] = $pdW['normal_price'] * $caseSize * $num_cases;
            $ins_array['regPrice'] = $pdW['normal_price'] * $caseSize * $num_cases;
            $ins_array['unitPrice'] = $pdW['normal_price'];
            if ($pdW['discount'] != 0 && $pdW['discounttype'] == 1) {
                /**
                  Only apply sale pricing from non-closeout batches
                  At WFC closeout happens to be batch type #11
                */
                $closeoutP = $dbc->prepare('
                    SELECT l.upc
                    FROM batchList AS l
                        INNER JOIN batches AS b ON l.batchID=b.batchID
                    WHERE l.upc=?
                        AND ' . $dbc->curdate() . ' >= b.startDate
                        AND ' . $dbc->curdate() . ' <= b.endDate
                        AND b.batchType=11
                ');
                $closeoutR = $dbc->execute($closeoutP, array($upc));
                if ($closeoutR && $dbc->num_rows($closeoutR) == 0) {
                    $ins_array['total'] = $pdW['special_price'] * $caseSize * $num_cases;
                    $ins_array['unitPrice'] = $pdW['special_price'];
                }
            } elseif ($mempricing) {
                if ($pdW['discounttype'] == 2) {
                    $ins_array['total'] = $pdW['special_price'] * $caseSize * $num_cases;
                    $ins_array['unitPrice'] = $pdW['special_price'];
                } elseif ($pdW['discounttype'] == 3) {
                    $ins_array['unitPrice'] = $pdW['normal_price'] * (1 - $pdW['special_price']);
                    $ins_array['total'] = $ins_array['unitPrice'] * $caseSize * $num_cases;
                } elseif ($pdW['discounttype'] == 5) {
                    $ins_array['unitPrice'] = $pdW['normal_price'] - $pdW['special_price'];
                    $ins_array['total'] = $ins_array['unitPrice'] * $caseSize * $num_cases;
                }
                if ($pdW['discount'] != 0 && $pdW['normal_price'] * $caseSize * $num_cases * 0.85 < $ins_array['total']) {
                    $ins_array['total'] = $pdW['normal_price'] * $caseSize * $num_cases * 0.85;
                    $ins_array['discounttype'] = 0;
                    $ins_array['unitPrice'] = $pdW['normal_price'];
                }
            }
        }
        $ins_array['description'] = substr($pdW['description'], 0, 32);
        /**
          If product has a default vendor, lookup
          vendor name and add it
        */
        if ($pdW['default_vendor_id'] != 0) {
            $v = new VendorsModel($dbc);
            $v->vendorID($pdW['default_vendor_id']);
            if ($v->load()) {
                $ins_array['mixMatch'] = substr($v->vendorName(), 0, 26);
            }
        }
        /**
          If no vendor name was found, try looking in prodExtra
        */
        if (empty($ins_array['mixMatch']) && $dbc->tableExists('prodExtra')) {
            $distP = $dbc->prepare('
                SELECT x.distributor
                FROM prodExtra AS x
                WHERE x.upc=?
            ');
            $distR = $dbc->execute($distP, array($upc));
            if ($distR && $dbc->num_rows($distR) > 0) {
                $distW = $dbc->fetch_row($distR);
                $ins_array['mixMatch'] = substr($distW['distributor'], 0, 26);
            }
        }
    } elseif ($srp != 0) {
        // use vendor SRP if applicable
        $ins_array['regPrice'] = $srp * $caseSize * $num_cases;
        $ins_array['total'] = $srp * $caseSize * $num_cases;
        $ins_array['unitPrice'] = $srp;
        if ($mempricing) {
            $ins_array['total'] *= 0.85;
        }
    }
    $tidP = $dbc->prepare_statement("SELECT MAX(trans_id),MAX(voided),MAX(numflag) \n            FROM {$TRANS}PendingSpecialOrder WHERE order_id=?");
    $tidR = $dbc->exec_statement($tidP, array($orderID));
    $tidW = $dbc->fetch_row($tidR);
    $ins_array['trans_id'] = $tidW[0] + 1;
    $ins_array['voided'] = $tidW[1];
    $ins_array['numflag'] = $tidW[2];
    $dbc->smart_insert("{$TRANS}PendingSpecialOrder", $ins_array);
    return array($qtyReq, $ins_array['trans_id'], $ins_array['description']);
}
Example #18
0
    function form_content()
    {
        $dbc = FannieDB::get($this->config->get('OP_DB'));
        ob_start();
        ?>
<form method = "get" action="<?php 
        echo $_SERVER['PHP_SELF'];
        ?>
">
<div class="col-sm-5">
    <div class="form-group">
        <label>Date Start</label>
            <input type=text id=date1 name=date1 
                class="form-control date-field" required />
    </div>
    <div class="form-group">
        <label>Date End</label>
            <input type=text id=date2 name=date2 
                class="form-control date-field" required />
    </div>
    <div class="form-group">
        <label>Vendor</label>
        <select name="vendorID" class="form-control">
        <option value="">All</option>
        <?php 
        $vendors = new VendorsModel($dbc);
        foreach ($vendors->find('vendorName') as $obj) {
            printf('<option value="%d">%s</option>', $obj->vendorID(), $obj->vendorName());
        }
        ?>
        </select>
    </div>
    <p>
        <button type="submit" class="btn btn-default btn-core">Submit</button>
        <button type="reset" class="btn btn-default btn-reset">Start Over</button>
    </p>
</div>
<div class="col-sm-5">
    <?php 
        echo FormLib::date_range_picker();
        ?>
                         
</div>
</form>
<?php 
        return ob_get_clean();
    }
Example #19
0
 public function get_view()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->OP_DB);
     $prep = $dbc->prepare("\n            SELECT superID,\n                super_name \n            FROM MasterSuperDepts\n            WHERE superID > 0\n            GROUP BY superID,\n                super_name");
     $res = $dbc->execute($prep);
     $opts = "<option value=99 selected>All</option>";
     while ($row = $dbc->fetch_row($res)) {
         $opts .= "<option value={$row['0']}>{$row['1']}</option>";
     }
     $vmodel = new VendorsModel($dbc);
     $vopts = "";
     foreach ($vmodel->find('vendorName') as $obj) {
         $vopts .= sprintf('<option value="%d">%s</option>', $obj->vendorID(), $obj->vendorName());
     }
     $queues = new ShelfTagQueuesModel($dbc);
     $qopts = $queues->toOptions();
     ob_start();
     ?>
     <form action=VendorPricingBatchPage.php method="get">
     <label>Select a Vendor</label>
     <select name="id" class="form-control">
     <?php 
     echo $vopts;
     ?>
     </select>
     <label>and a Super Department</label>
     <select name=super class="form-control">
     <?php 
     echo $opts;
     ?>
     </select>
     <label>Show all items</label>
     <select name=filter class="form-control">
     <option>No</option>
     <option>Yes</option>
     </select>
     <label>Shelf Tag Queue</label>
     <select name="queueID" class="form-control">
     <?php 
     echo $qopts;
     ?>
     </select>
     <br />
     <p>
     <button type=submit class="btn btn-default">Continue</button>
     </p>
     </form>
     <?php 
     return ob_get_clean();
 }