protected function xlsxToArray($limit) { return \COREPOS\Fannie\API\data\FileData::xlsxToArray($this->upload_file_name, $limit); }
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; }