// You should have received a copy of the GNU General Public License // along with Pastèque. If not, see <http://www.gnu.org/licenses/>. namespace BaseStocks; $message = null; $error = null; $modules = \Pasteque\get_loaded_modules(\Pasteque\get_user_id()); $multilocations = false; $locSrv = new \Pasteque\LocationsService(); $locations = $locSrv->getAll(); $defaultLocationId = $locations[0]->id; if (in_array("stock_multilocations", $modules)) { $multilocations = true; } $dateStr = isset($_POST['date']) ? $_POST['date'] : \i18nDate(time()); $time = \i18nRevDate($dateStr); if (isset($_POST['reason']) && !isset($_POST['sendCsv'])) { $reason = $_POST['reason']; if ($multilocations) { $locationId = $_POST['location']; } else { $locationId = $defaultLocationId; } foreach ($_POST as $key => $value) { if (strpos($key, "qty-") === 0) { $productId = substr($key, 4); $product = \Pasteque\ProductsService::get($productId); switch ($reason) { case \Pasteque\StockMove::REASON_OUT_SELL: case \Pasteque\StockMove::REASON_IN_REFUND: $price = $product->priceSell;
$tariffAreaId = null; if ($tariffAreas && $_POST['tariffAreaId'] !== "") { $tariffAreaId = $_POST['tariffAreaId']; } $maxDebt = 0.0; if ($_POST['maxDebt'] !== "") { $maxDebt = $_POST['maxDebt']; } $prepaid = 0.0; if ($_POST['prepaid'] != "") { $prepaid = $_POST['prepaid']; } $expireDate = NULL; if (isset($_POST['expireDate']) && $_POST['expireDate'] != "") { $expireDate = $_POST['expireDate']; $expireDate = \i18nRevDate($expireDate); } $cust = new \Pasteque\Customer($number, $key, $_POST['dispName'], $_POST['card'], $taxCatId, $discountProfileId, $tariffAreaId, $prepaid, $maxDebt, $currDebt, $debtDate, $_POST['firstName'], $_POST['lastName'], $_POST['email'], $_POST['phone1'], $_POST['phone2'], $_POST['fax'], $_POST['addr1'], $_POST['addr2'], $_POST['zipCode'], $_POST['city'], $_POST['region'], $_POST['country'], $_POST['note'], $visible, $expireDate); $id = \Pasteque\CustomersService::create($cust); if ($id !== false) { $message = \i18n("Customer saved. <a href=\"%s\">Go to the customer page</a>.", PLUGIN_NAME, \Pasteque\get_module_url_action(PLUGIN_NAME, 'customer_edit', array('id' => $id))); } else { $error = \i18n("Unable to save changes"); } } } $cust = null; $currDebt = ""; $prepaid = 0; $str_debtDate = ""; $str_expireDate = "";
/** Display a chart. * @param $chart chart data, as given by get_chart */ function tpl_chart($chart) { // Read values $values = array(); foreach ($chart->getParams() as $param) { $id = $param['param']; if (isset($_POST[$id]) || isset($_GET[$id])) { if (isset($_POST[$id])) { $val = $_POST[$id]; } else { $val = $_GET[$id]; } $db = DB::get(); switch ($param['type']) { case DB::DATE: // Revert the i18n input to timestamp $values[$id] = \i18nRevDate($val); break; default: $values[$id] = $val; break; } } else { $default = $chart->getDefault($id); if ($default !== null) { $values[$id] = $default; } else { // TODO: error } } } // Display __tpl_chart_title($chart); __tpl_chart_input($chart, $values); $run = $chart->run($values); $par = FALSE; if ($run->isEmpty()) { echo "<div class=\"information\">" . \i18n("No result") . "</div>"; return; } __tpl_chart($chart->getHeaders(), $chart->getDatasets()); }
} } else { $error++; $error_mess[] = \i18n("On line %d: Category parent doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber()); } } $message = \i18n("%d line(s) inserted, %d line(s) modified, %d error(s)", PLUGIN_NAME, $create, $update, $error); $csv->close(); \Pasteque\tpl_msg_box($message, $error_mess); } ?> <?php if (isset($_FILES['csv'])) { $dateStr = isset($_POST['date']) ? $_POST['date'] : \i18nDate(time()); $dateStr = \i18nRevDate($dateStr); $date = \Pasteque\stdstrftime($dateStr); $csv = init_csv(); if ($csv === NULL) { \Pasteque\tpl_msg_box(NULL, \i18n("Selected file empty or bad format", PLUGIN_NAME)); } else { if (!$csv->isOpen()) { $err = array(); foreach ($csv->getErrors() as $mess) { $err[] = \i18n($mess); } \Pasteque\tpl_msg_box(NULL, $err); } else { import_csv($csv, $date); } }
} // Update $taxCatId = \Pasteque\TaxesService::updateCat($taxCat); if ($taxCatId === false) { $error = \i18n("Unable to save tax.", PLUGIN_NAME); } if ($error === null) { $message = \i18n("Tax saved", PLUGIN_NAME); } } else { if (isset($_POST['label'])) { // Create tax category if (!isset($_POST['new-startDate'])) { $start = \time(); } else { $start = \i18nRevDate($_POST['new-startDate']); } $taxCat = new \Pasteque\TaxCat($_POST['label']); $tax = new \Pasteque\Tax(null, $_POST['label-new'], $start, floatval($_POST['rate-new'])); $taxCat->addTax($tax); $taxCatId = \Pasteque\TaxesService::createCat($taxCat); if ($taxCatId === false) { $error = \i18n("Unable to save tax.", PLUGIN_NAME); } else { $message = \i18n("Tax saved", PLUGIN_NAME); } } } $taxCat = null; if (isset($_GET['id'])) { $taxCat = \Pasteque\TaxesService::get($_GET['id']);