Exemplo n.º 1
0
 /**
  * @param $CSA
  * @return array
  */
 private function handleShopAdmin($CSA)
 {
     $aSData = [];
     $aData = [];
     if (!isset($_GET["action"])) {
         $bIgnoreStorno = false;
         $sql = 'SELECT * FROM orders WHERE ';
         if (!isset($_REQUEST["type"]) or $_REQUEST["type"] == 'openinwork') {
             $sql .= "(o_ordercompleted = 'n' OR o_ordercompleted = 'i') ";
         } elseif ($_REQUEST["type"] == 'closed') {
             $sql .= "o_ordercompleted = 'y' ";
         } elseif ($_REQUEST["type"] == 'open') {
             $sql .= "o_ordercompleted = 'n' ";
         } elseif ($_REQUEST["type"] == 'inwork') {
             $sql .= "o_ordercompleted = 'i' ";
         } elseif ($_REQUEST["type"] == 'storno') {
             $sql .= "o_ordercompleted = 's' ";
         } elseif ($_REQUEST["type"] == 'deleted') {
             $sql .= "o_ordercompleted = 'd' ";
         } elseif ($_REQUEST["type"] == 'all') {
             $sql .= "o_ordercompleted != 'd' ";
             $bIgnoreStorno = true;
         } else {
             die(HardcodedText::get('shopadmin_error_invalidrequest'));
         }
         $bFromTo = false;
         $sFrom = null;
         $sTo = null;
         if (isset($_REQUEST["type"]) && ($_REQUEST["type"] == 'deleted' or $_REQUEST["type"] == 'all' or $_REQUEST["type"] == 'closed')) {
             $sql .= "AND ";
             $sFrom = \filter_var($_REQUEST["fromyear"], FILTER_SANITIZE_NUMBER_INT) . '-' . Tools::dateAddLeadingZero(\filter_var($_REQUEST["frommonth"], FILTER_SANITIZE_NUMBER_INT));
             $sFrom .= '-' . Tools::dateAddLeadingZero(\filter_var($_REQUEST["fromday"], FILTER_SANITIZE_NUMBER_INT));
             $sTo = \filter_var($_REQUEST["toyear"], FILTER_SANITIZE_NUMBER_INT) . '-' . Tools::dateAddLeadingZero(\filter_var($_REQUEST["tomonth"], FILTER_SANITIZE_NUMBER_INT));
             $sTo .= '-' . Tools::dateAddLeadingZero(\filter_var($_REQUEST["today"], FILTER_SANITIZE_NUMBER_INT));
             $sql .= "o_orderdate >= :from ";
             $sql .= "AND o_orderdate <= :to ";
             $bFromTo = true;
         }
         $sql .= "ORDER BY o_ordertimestamp DESC";
         $hResult = $this->db->prepare($sql);
         if ($bFromTo) {
             $hResult->bindValue(':from', $sFrom);
             $hResult->bindValue(':to', $sTo);
         }
         $hResult->execute();
         if ($hResult->rowCount() != 0) {
             $i = 0;
             $j = 0;
             $k = 0;
             $fGesamtnetto = 0.0;
             while ($aRow = $hResult->fetch()) {
                 if ($aRow["o_ordercompleted"] == 'y') {
                     $sStatus = '<span style="color: green; font-weight: bold;">' . HardcodedText::get('shopadmin_orderstatus_completed') . '</span>';
                 } elseif ($aRow["o_ordercompleted"] == 'n') {
                     $sStatus = '<span style="color: orange; font-weight: bold;">' . HardcodedText::get('shopadmin_orderstatus_open') . '</span>';
                 } elseif ($aRow["o_ordercompleted"] == 'i') {
                     $sStatus = '<span style="color: orange;">' . HardcodedText::get('shopadmin_orderstatus_inwork') . '</span>';
                 } elseif ($aRow["o_ordercompleted"] == 's') {
                     $sStatus = '<span style="color: red; font-weight: bold;">' . HardcodedText::get('shopadmin_orderstatus_canceled') . '</span>';
                 } elseif ($aRow["o_ordercompleted"] == 'd') {
                     $sStatus = HardcodedText::get('shopadmin_orderstatus_deleted');
                 } else {
                     $sStatus = '';
                 }
                 if ($aRow["o_paymentcompleted"] == 'y') {
                     $sZahlungsmethode = '<span style="color: green;">';
                 } else {
                     $sZahlungsmethode = '<span style="color: red;">';
                 }
                 $mZahlungsmethode = $this->serviceManager->get('textcats')->T("order_paymentmethod_" . $aRow["o_paymentmethod"], true);
                 if ($mZahlungsmethode) {
                     $sZahlungsmethode .= $mZahlungsmethode;
                 } else {
                     $sZahlungsmethode .= ucwords($aRow["o_paymentmethod"]);
                 }
                 $sZahlungsmethode .= '</span>';
                 if (trim($aRow["o_corpname"]) == '') {
                     $sName = $aRow["o_name"];
                 } else {
                     $sName = $aRow["o_corpname"];
                 }
                 $aData[] = ['o_id' => $aRow["o_id"], 'o_account_no' => $aRow["o_custno"], 'o_email' => $aRow["o_email"], 'o_cust' => $sName . '<br>' . $aRow["o_zip"] . ' ' . $aRow["o_town"], 'o_authed' => $aRow["o_authed"], 'o_sumnettoall' => number_format($aRow["o_sumnettoall"], HelperConfig::$core['numberformat_decimals'], HelperConfig::$core['numberformat_decimal_point'], HelperConfig::$core['numberformat_thousands_seperator']) . ' ' . HelperConfig::$shop["waehrungssymbol"] . ($aRow["o_mindermenge"] != 0 && $aRow["o_mindermenge"] != '' ? '<br>+' . number_format($aRow["o_mindermenge"], HelperConfig::$core['numberformat_decimals'], HelperConfig::$core['numberformat_decimal_point'], HelperConfig::$core['numberformat_thousands_seperator']) . ' ' . HelperConfig::$shop["waehrungssymbol"] : ''), 'o_order_status' => $sStatus . (trim($aRow["o_lastedit_user"]) != '' ? '<br>' . $aRow["o_lastedit_user"] : ''), 'o_ordertime_number' => date(HelperConfig::$core['locale_format_date_time'], $aRow["o_ordertimestamp"]) . (trim($aRow["o_transaction_no"]) != '' ? '<br>' . $aRow["o_transaction_no"] : ''), 'o_order_host_payment' => $sZahlungsmethode . '<br>' . $aRow["o_srv_hostname"]];
                 if (!($aRow["o_ordercompleted"] == 's' && $bIgnoreStorno)) {
                     $fGesamtnetto += $aRow["o_sumnettoall"];
                     $j++;
                 } else {
                     $k++;
                 }
                 $i++;
             }
             $aSData['listtable_orders'] = Tools::makeListtable($CSA["list_orders"], $aData, $this->serviceManager->get('twig'));
             $aSData['listtable_i'] = $i;
             $aSData['listtable_j'] = $j;
             $aSData['listtable_k'] = $k;
             $aSData['listtable_gesamtnetto'] = $fGesamtnetto;
         } else {
             $aSData['nomatchingordersfound'] = true;
         }
     } elseif (isset($_GET["action"]) && $_GET["action"] == 'edit') {
         $iId = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
         $sql = 'SELECT * FROM orders WHERE o_id = :id';
         /** @var \PDOStatement $hResult */
         $hResult = $this->db->prepare($sql);
         $hResult->bindValue(':id', $iId);
         $hResult->execute();
         if ($hResult->rowCount() == 1) {
             $aSData["orderdata"] = $hResult->fetch();
             $sql = 'SELECT * FROM orders_items WHERE oi_o_id = :id';
             $hResult = $this->db->prepare($sql);
             $hResult->bindValue(':id', $iId);
             $hResult->execute();
             $aItems = $hResult->fetchAll();
             $aUserdata = ['cust_no' => $aSData["orderdata"]["o_custno"], 'cust_email' => $aSData["orderdata"]["o_email"], 'cust_corp' => $aSData["orderdata"]["o_corpname"], 'cust_name' => $aSData["orderdata"]["o_name"], 'cust_street' => $aSData["orderdata"]["o_street"], 'cust_zip' => $aSData["orderdata"]["o_zip"], 'cust_town' => $aSData["orderdata"]["o_town"], 'cust_phone' => $aSData["orderdata"]["o_phone"], 'cust_cellphone' => $aSData["orderdata"]["o_cellphone"], 'cust_fax' => $aSData["orderdata"]["o_fax"], 'cust_country' => $aSData["orderdata"]["o_country"], 'cust_group' => $aSData["orderdata"]["o_group"]];
             $aSData["customerform"] = \HaaseIT\HCSF\Customer\Helper::buildCustomerForm(HelperConfig::$lang, 'shopadmin', '', $aUserdata);
             $aSData["orderdata"]["options_shippingservices"] = [''];
             foreach (HelperConfig::$shop["shipping_services"] as $sValue) {
                 $aSData["orderdata"]["options_shippingservices"][] = $sValue;
             }
             $aItemsCarttable = [];
             foreach ($aItems as $aValue) {
                 $aPrice = ['netto_list' => $aValue["oi_price_netto_list"], 'netto_sale' => $aValue["oi_price_netto_sale"], 'netto_rebated' => $aValue["oi_price_netto_rebated"], 'netto_use' => $aValue["oi_price_netto_use"], 'brutto_use' => $aValue["oi_price_brutto_use"]];
                 //$aPrice = $oItem->calcPrice($aValue["oi_price_netto"], HelperConfig::$shop["vat"][$aValue["oi_vat_id"]], '', true);
                 $aItemsCarttable[$aValue["oi_cartkey"]] = ['amount' => $aValue["oi_amount"], 'price' => $aPrice, 'vat' => $aValue["oi_vat"], 'rg' => $aValue["oi_rg"], 'rg_rebate' => $aValue["oi_rg_rebate"], 'name' => $aValue["oi_itemname"], 'img' => $aValue["oi_img"]];
             }
             $aSData = array_merge(\HaaseIT\HCSF\Shop\Helper::buildShoppingCartTable($aItemsCarttable, true, $aSData["orderdata"]["o_group"], '', $aSData["orderdata"]["o_vatfull"], $aSData["orderdata"]["o_vatreduced"]), $aSData);
         } else {
             $aSData['ordernotfound'] = true;
         }
     }
     return $aSData;
 }