function import_csv($csv)
{
    $error = 0;
    $create = 0;
    $update = 0;
    $error_mess = array();
    while ($tab = $csv->readLine()) {
        //init optionnal values
        $AllKeyPossible = array_merge($csv->getKeys(), $csv->getOptionalKeys());
        $tab = initArray($AllKeyPossible, $tab);
        //check
        $category = \Pasteque\CategoriesService::getByName($tab['category']);
        $taxCat = \Pasteque\TaxesService::getByName($tab['tax_cat']);
        if ($taxCat && $category) {
            $prod = readProductLine($tab, $category, $taxCat);
            $product_exist = \Pasteque\ProductsService::getByRef($prod->reference);
            if ($product_exist !== null) {
                // update product
                $prod->id = $product_exist->id;
                $prod = mergeProduct($product_exist, $prod);
                //if update imposible an is occurred
                if (!\Pasteque\ProductsService::update($prod)) {
                    $error++;
                    $error_mess[] = \i18n("On line %d: " . "Cannot update product: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['label']);
                } else {
                    // update stock_curr and stock_diary
                    manage_stock_level($prod->id, $tab, FALSE);
                    $update++;
                }
            } else {
                // create product
                $id = \Pasteque\ProductsService::create($prod);
                if ($id) {
                    //create stock_curr and stock diary
                    manage_stock_level($id, $tab, TRUE);
                    $create++;
                } else {
                    $error++;
                    $error_mess[] = \i18n("On line %d: " . "Cannot create product: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['label']);
                }
            }
        } else {
            // Missing category or tax category
            $error++;
            if (!$category) {
                $error_mess[] = \i18n("On line %d " . "category: '%s' doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['category']);
            }
            if (!$taxCat) {
                $error_mess[] = \i18n("On line %d: " . "Tax category: '%s' doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['tax_cat']);
            }
        }
    }
    $message = \i18n("%d line(s) inserted, %d line(s) modified, %d error(s)", PLUGIN_NAME, $create, $update, $error);
    return array($message, $error_mess);
}
Example #2
0
function pdf_barcode($pdf, $productId, $col, $row)
{
    $product = \Pasteque\ProductsService::get($productId);
    $x = H_MARGIN + $col * COL_SIZE + $col * H_PADDING;
    $y = V_MARGIN + $row * ROW_SIZE + $row * V_PADDING;
    $pdf->SetXY($x, $y);
    $pdf->Cell(BARCODE_WIDTH, TEXT_HEIGHT, utf8_decode($product->reference), 0, 1, "C");
    $pdf->SetXY($x, $y + TEXT_HEIGHT);
    $data = \Barcode::fpdf($pdf, "000000", $pdf->GetX() + BARCODE_WIDTH / 2, $pdf->GetY() + BARCODE_HEIGHT / 2, 0, "ean13", array('code' => $product->barcode), BARCODE_WIDTH / (15 * 7), BARCODE_HEIGHT);
    $pdf->SetXY($x, $y + BARCODE_HEIGHT + TEXT_HEIGHT);
    $pdf->Cell(BARCODE_WIDTH, TEXT_HEIGHT, $product->barcode, 0, 1, "C");
}
Example #3
0
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Pastèque is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    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 ProductBarcodes;

$message = NULL;
$error = NULL;
$categories = \Pasteque\CategoriesService::getAll();
$allProducts = \Pasteque\ProductsService::getAll(TRUE);
$products = array();
foreach ($allProducts as $product) {
    if ($product->barcode !== NULL && $product->barcode != "") {
        $products[] = $product;
    }
}
?>
<h1><?php 
\pi18n("Tags", PLUGIN_NAME);
?>
</h1>

<?php 
\Pasteque\tpl_msg_box($message, $error);
?>
Example #4
0
}
$locSrv = new \Pasteque\LocationsService();
$locations = $locSrv->getAll();
$locNames = array();
$locIds = array();
foreach ($locations as $location) {
    $locNames[] = $location->label;
    $locIds[] = $location->id;
}
$currLocation = null;
if (isset($_POST['location'])) {
    $currLocation = $_POST['location'];
} else {
    $currLocation = $locations[0]->id;
}
$products = \Pasteque\ProductsService::getAll(true);
$categories = \Pasteque\CategoriesService::getAll();
$prdCat = array();
// Link products to categories and don't track compositions
foreach ($products as $product) {
    if ($product->categoryId !== \Pasteque\CompositionsService::CAT_ID) {
        $prdCat[$product->categoryId][] = $product;
    }
}
$levels = \Pasteque\StocksService::getLevels($currLocation);
$prdLevel = array();
foreach ($levels as $level) {
    $prdLevel[$level->productId] = $level;
}
?>
<h1><?php 
Example #5
0
            }
            $prd = new \Pasteque\Product($_POST['reference'], $_POST['label'], $_POST['realsell'], $catId, $provId, $disp_order, $taxCatId, $visible, $scaled, $_POST['priceBuy'], $attr, $_POST['barcode'], $img !== null, $discount_enabled, $discount_rate);
            $id = \Pasteque\ProductsService::create($prd, $img);
            if ($id !== FALSE) {
                $message = \i18n("Product saved. <a href=\"%s\">Go to the product page</a>.", PLUGIN_NAME, \Pasteque\get_module_url_action(PLUGIN_NAME, 'product_edit', array('id' => $id)));
            } else {
                $error = \i18n("Unable to save changes");
            }
        }
    }
}
$product = NULL;
$vatprice = "";
$price = "";
if (isset($_GET['id'])) {
    $product = \Pasteque\ProductsService::get($_GET['id']);
    $taxCat = \Pasteque\TaxesService::get($product->taxCatId);
    $tax = $taxCat->getCurrentTax();
    $vatprice = $product->priceSell * (1 + $tax->rate);
    $price = sprintf("%.2f", $product->priceSell);
}
$taxes = \Pasteque\TaxesService::getAll();
$categories = \Pasteque\CategoriesService::getAll();
$providers = \Pasteque\ProvidersService::getAll();
$level = NULL;
if ($stocks === TRUE && $product != NULL) {
    $level = \Pasteque\StocksService::getLevel($product->id);
}
?>
<h1><?php 
\pi18n("Edit a product", PLUGIN_NAME);
Example #6
0
/** Main csv import function given a csv object */
function import_csv($csv)
{
    $error = 0;
    $creations = 0;
    $updates = 0;
    $error_mess = array();
    $srv = new \Pasteque\TariffAreasService();
    $allAreas = $srv->getAll();
    $taxCats = \Pasteque\TaxesService::getAll();
    $areas = array();
    $areasRef = array();
    while ($tab = $csv->readLine()) {
        //check
        $area = null;
        $ref = null;
        if (isset($areas[$tab['area']])) {
            $area = $areas[$tab['area']];
            $ref = $areasRef[$tab['area']];
        } else {
            foreach ($allAreas as $a) {
                if ($a->label == $tab['area']) {
                    // Set reference for update and recreate a new to
                    // delete non imported prices
                    $areasRef[$tab['area']] = $a;
                    $area = \Pasteque\TariffArea::__build($a->id, $a->label, $a->dispOrder);
                    $areas[$tab['area']] = $area;
                    break;
                }
            }
        }
        // Create area if not found
        if ($area === null) {
            $area = new \Pasteque\TariffArea($tab['area'], 100);
            $area->id = $srv->create($area);
            if ($area->id === false) {
                $error++;
                $error_mess[] = \i18n("Line %d: Unable to create area %s", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['area']);
                continue;
            }
            $areas[$tab['area']] = $area;
            $areasRef[$tab['area']] = null;
        }
        $product = \Pasteque\ProductsService::getByRef($tab['reference']);
        if ($product === null) {
            $error++;
            $error_mess[] = \i18n("Line %d: '%s' doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['reference']);
            continue;
        }
        $taxCat = null;
        foreach ($taxCats as $tc) {
            if ($tc->id == $product->taxCatId) {
                $taxCat = $tc;
                break;
            }
        }
        // Check if price should be updated
        $priceFound = false;
        $sellPrice = $tab['sellVat'] / (1 + $taxCat->getCurrentTax()->rate);
        if ($ref !== null) {
            foreach ($ref->getPrices() as $price) {
                if ($price->productId == $product->id) {
                    // Update
                    $area->addPrice($product->id, $sellPrice);
                    $priceFound = true;
                    $updates++;
                    break;
                }
            }
        }
        if (!$priceFound) {
            // Add a price
            $area->addPrice($product->id, $sellPrice);
            $creations++;
        }
    }
    // Update data
    foreach ($areas as $name => $area) {
        if ($srv->update($area) === false) {
            $error++;
            $error_message[] = \i18n("Unable to save tariff area %d", PLUGIN_NAME, $name);
        }
    }
    $message = \i18n("%d line(s) inserted, %d line(s) modified, %d error(s)", PLUGIN_NAME, $creations, $updates, $error);
    return array($message, $error_mess);
}
Example #7
0
			// Add line
			var html = "<tr id=\"line-" + product['id'] + "\">\n";
			html += "<td><img class=\"thumbnail\" src=\"" + product['img'] + "\" /></td>\n";
			html += "<td>" + product['reference'] + "</td>\n";
			html += "<td>" + product['label'] + "</td>\n";
			html += "<td>" + product['vatSell'] + "</td>\n";
			html += "<td class=\"price-cell\"><input class=\"price\" id=\"line-" + product['id'] + "\" type=\"numeric\" name=\"price-" + product['id'] + "\" value=\"" + price + "\" />\n";
			html += "<td><a class=\"btn-delete\" href=\"\" onClick=\"javascript:deleteLine('" + product['id'] + "');return false;\"><?php 
\pi18n("Delete");
?>
</a></td>\n";
			html += "</tr>\n"; 
			jQuery("#list").append(html);
		}
    }

    jQuery(document).ready(function() {
<?php 
if ($area !== null) {
    foreach ($area->getPrices() as $price) {
        $product = \Pasteque\ProductsService::get($price->productId);
        $taxCat = \Pasteque\TaxesService::get($product->taxCatId);
        $tax = $taxCat->getCurrentTax();
        $vatPrice = $price->price * (1 + $tax->rate);
        echo "\t\tinitProduct(\"" . $price->productId . "\", " . $vatPrice . ");\n";
    }
}
?>
    });
</script>
<?php 
Example #8
0
}
if (!isset($_GET["hidden"])) {
    $hidden = true;
} else {
    $hidden = $_GET["hidden"];
}
if ($range == "all") {
    $products = \Pasteque\ProductsService::getAll($hidden);
    $totalProducts = \Pasteque\ProductsService::getTotal($hidden);
} else {
    if (isset($_GET["category"])) {
        $products = \Pasteque\ProductsService::getByCategory($_GET["category"]);
        $totalProducts = \Pasteque\ProductsService::getTotalByCategory($_GET["category"], $hidden);
    } else {
        $products = \Pasteque\ProductsService::getRange($range, $start, $hidden);
        $totalProducts = \Pasteque\ProductsService::getTotal($hidden);
    }
}
$categories = \Pasteque\CategoriesService::getAll();
$prdCat = array();
$archivesCat = array();
foreach ($products as $product) {
    if ($product->categoryId !== \Pasteque\CompositionsService::CAT_ID) {
        $prdCat[$product->categoryId][] = $product;
    }
    // Archive will be filled on display loop
}
?>
<h1><?php 
\pi18n("Products", PLUGIN_NAME);
?>
Example #9
0
 public function __construct($report, $values)
 {
     $this->data = array();
     $this->i = 0;
     $countedStock = array();
     if (!isset($values['location'])) {
         $locSrv = new \Pasteque\LocationsService();
         $locations = $locSrv->getAll();
         $defaultLocationId = $locations[0]->id;
         $values['location'] = $defaultLocationId;
     }
     foreach ($values as $key => $value) {
         if (strpos($key, "qty-") === 0) {
             $productId = substr($key, 4);
             $qty = $value;
             $countedStock[$productId] = $qty;
         }
     }
     $categories = \Pasteque\CategoriesService::getAll();
     $products = \Pasteque\ProductsService::getAll(TRUE);
     $prdCat = array();
     // Build listing by categories
     foreach ($products as $product) {
         if ($product->categoryId !== \Pasteque\CompositionsService::CAT_ID) {
             $prdCat[$product->categoryId][] = $product;
         }
     }
     // Get stock to compare with counted stock
     $levels = array();
     $rawLevels = \Pasteque\StocksService::getLevels($values['location']);
     foreach ($rawLevels as $level) {
         $levels[$level->productId] = $level;
     }
     foreach ($categories as $category) {
         if (isset($prdCat[$category->id])) {
             foreach ($prdCat[$category->id] as $product) {
                 $counted = 0;
                 if (isset($countedStock[$product->id])) {
                     $counted = $countedStock[$product->id];
                 }
                 $actual = 0;
                 if (isset($levels[$product->id])) {
                     $actual = $levels[$product->id]->qty;
                 }
                 if ($counted !== $actual) {
                     $this->data[] = array("ref" => $product->reference, "counted" => $counted, "actual" => $actual, "diff" => $counted - $actual);
                 }
             }
         }
     }
 }