Example #1
0
$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 
\pi18n("Inventory", PLUGIN_NAME);
?>
</h1>

<?php 
if ($multilocations) {
    // Location picker
    ?>
<form class="edit" action="<?php 
Example #2
0
                } else {
                    $error = \i18n("Unable to save changes");
                }
            } else {
                if ($reason == \Pasteque\StockMove::REASON_RESET) {
                    $level = \Pasteque\StocksService::getLevel($productId, $locationId, null);
                    $move = new \Pasteque\StockMove($time, $reason, $productId, $locationId, null, -$level->qty, $price);
                    $move2 = new \Pasteque\StockMove($time, $reason, $productId, $locationId, null, $qty, $price);
                    if (\Pasteque\StocksService::addMove($move) && \Pasteque\StocksService::addMove($move2)) {
                        $message = \i18n("Changes saved");
                    } else {
                        $error = \i18n("Unable to save changes");
                    }
                } else {
                    $move = new \Pasteque\StockMove($time, $reason, $productId, $locationId, null, $qty, $price);
                    if (\Pasteque\StocksService::addMove($move)) {
                        $message = \i18n("Changes saved");
                    } else {
                        $error = \i18n("Unable to save changes");
                    }
                }
            }
        }
    }
} else {
    if (isset($_POST['sendCsv'])) {
        $key = array('Quantity', 'Reference');
        $csv = new \Pasteque\Csv($_FILES['csv']['tmp_name'], $key, array(), PLUGIN_NAME);
        if (!$csv->open()) {
            $error = $csv->getErrors();
        } else {
Example #3
0
$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);
?>
</h1>

<?php 
\Pasteque\tpl_msg_box($message, $error);
?>

<form class="edit" action="<?php 
echo \Pasteque\get_current_url();
?>
" method="post" enctype="multipart/form-data">
/** Manage stockDiary and stockCurr whith id and location by default:"Principal"
 * check if fields 'stock_min' and 'stock_max' are set in array
 * if $create is true create a new entry in stockDiary and stockCurr in BDD
 * else update stockDiarry and  stockCurr.
 */
function manage_stock_level($id, $array)
{
    $level = \Pasteque\StocksService::getLevel($id, "0", null);
    $min = null;
    $max = null;
    if (isset($array['stock_min'])) {
        $min = $array['stock_min'];
    }
    if (isset($array['stock_max'])) {
        $max = $array['stock_max'];
    }
    if ($level !== null) {
        // Update existing level
        if ($min !== null) {
            $level->security = $min;
        }
        if ($max !== null) {
            $level->max = $max;
        }
        return \Pasteque\StocksService::updateLevel($level);
    } else {
        // Create a new level
        $level = new \Pasteque\StockLevel($id, "0", null, $min, $max);
        return \Pasteque\StocksService::createLevel($level);
    }
}
Example #5
0
$locIds = array();
foreach ($locations as $location) {
    $locNames[] = $location->label;
    $locIds[] = $location->id;
}
$prdCat = array();
$levels = array();
if ($countedStock !== null) {
    // 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
    $rawLevels = \Pasteque\StocksService::getLevels($locationId);
    foreach ($rawLevels as $level) {
        $levels[$level->productId] = $level;
    }
}
?>
<h1><?php 
\pi18n("Stock check", PLUGIN_NAME);
?>
</h1>

<?php 
\Pasteque\tpl_msg_box($message, $error);
?>

<?php 
Example #6
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);
                 }
             }
         }
     }
 }