/** * get collection of all rentals for start & end date * * @param $startDate * @param $endDate */ public function getCollection($startDate, $endDate, $isByOrder = false) { $reserveOrderCollection = Mage::getModel('payperrentals/reservationorders')->getCollection(); if (Mage::helper('itwebcommon')->isVendorAdmin()) { $reserveOrderCollection->addFieldToFilter('main_table.vendor_id', array('eq' => Mage::getSingleton('vendors/session')->getId())); } $reserveOrderCollection->addHavingFilter("main_table.start_turnover_before >= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($startDate) . "' AND main_table.end_turnover_after <= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($endDate) . "'"); $reserveOrderCollection->getSelect()->joinLeft(array('soi' => Mage::getConfig()->getTablePrefix() . 'sales_flat_order_item'), 'soi.item_id=order_item_id', array('name')); $reserveOrderCollection->getSelect()->joinLeft(array('so' => Mage::getConfig()->getTablePrefix() . 'sales_flat_order'), 'so.entity_id=main_table.order_id', array('customer_firstname', 'customer_lastname', 'increment_id')); // $reserveOrderCollection->getSelect()->join(array('product' => 'catalog_product_flat_1'),'product.entity_id=main_table.product_id','name'); // $reserveOrderCollection->getSelect()->group('main_table.order_id'); return $reserveOrderCollection; }
/** * Function to get if product is available between dates * * @param $productId * @param int $qty * @param $startDate * @param $endDate * * @return bool */ public function isAvailable($productId, $startDate, $endDate, $qty, $quoteItem = false) { if (self::isAllowedOverbook($productId)) { return true; } if ($quoteItem) { $collectionQuotes = Mage::getModel('payperrentals/reservationquotes')->getCollection()->addProductIdFilter($productId)->addSelectFilter("start_date = '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($startDate) . "' AND end_date = '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($endDate) . "' AND quote_item_id = '" . $quoteItem->getId() . "'"); $oldQty = 0; foreach ($collectionQuotes as $oldQuote) { $oldQty = $oldQuote->getQty(); } if (Mage::app()->getRequest()->getParam('qty')) { $oldQty = 0; } $qty = $qty - $oldQty; } $maxQty = self::getQuantity($productId, $startDate, $endDate); if ($maxQty < $qty) { return false; } return true; }
public function deleteByQuoteItemAndDates(Mage_Sales_Model_Quote_Item $QuoteItem, $start_date, $end_date) { $condition = "quote_item_id=" . intval($QuoteItem->getId()) . ' AND start_date="' . ITwebexperts_Payperrentals_Helper_Date::toDbDate($start_date) . '" AND end_date="' . ITwebexperts_Payperrentals_Helper_Date::toDbDate($end_date) . '"'; $this->_getWriteAdapter()->delete($this->getMainTable(), $condition); return $this; }
public function addBetweenDatesFilter($start_date) { $this->getSelect()->where('date(start_date) <= date("' . ITwebexperts_Payperrentals_Helper_Date::toDbDate($start_date) . '")')->where('date(end_date) >= date("' . ITwebexperts_Payperrentals_Helper_Date::toDbDate($start_date) . '")'); return $this; }
public function getToSendCollection($startDatefrom, $startDateto, $endDatefrom, $endDateto, $forStore) { $this->addSelectFilter("start_date >= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($startDatefrom) . "' AND start_date <= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($startDateto) . "'")->addSelectFilter("end_date >= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($endDatefrom) . "' AND end_date <= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($endDateto) . "'")->addSelectFilter("main_table.qty >= main_table.qty_shipped")->addSelectFilter("product_type = '" . ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE . "'")->addFieldToFilter('main_table.order_id', array('neq' => 0))->groupByOrderId(); if ($forStore) { $this->getSelect()->joinLeft(array('so' => Mage::getSingleton('core/resource')->getTableName('sales_flat_order')), 'main_table.order_id = ' . 'so.entity_id', array('so.store_id as store_id')); $this->getSelect()->where('so.store_id=?', $this->getRequest()->getParam('forStore')); } //echo $this->getSelect(); return $this; }
/** * @param bool $isExtended */ private static function getReservationItemsToBeReturnedForCustomerEmail($isExtended = false) { $reminderPerCustomer = array(); $startDate = date('Y-m-d', strtotime('-3 day', strtotime(date('Y-m-d')))); //$startDate = date('Y-m-d'); if (!$isExtended) { $endDate = date('Y-m-d', strtotime('+' . Mage::getStoreConfig(self::XML_PATH_REMINDER_DAYS) . ' day', strtotime(date('m/d/Y')))); } else { $endDate = date('Y-m-d', strtotime('+' . Mage::getStoreConfig(self::XML_PATH_EXTENDED_REMINDER_DAYS) . ' day', strtotime(date('m/d/Y')))); } $collReservationToBeReturned = Mage::getModel('payperrentals/sendreturn')->getCollection()->addSelectFilter("res_enddate >= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($startDate) . "' AND res_enddate <= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($endDate) . "' AND return_date='0000-00-00 00:00:00'")->groupByOrder(); $clientListIncoming = '<ul>'; $listIncoming = ''; $nrIncoming = 0; $usedOrders = array(); foreach ($collReservationToBeReturned as $item) { $order = Mage::getModel('sales/order')->load($item->getOrderId()); $customer = Mage::getModel('customer/customer')->load($order->getCustomerId()); if (isset($usedOrders[$customer->getEmail()]) && in_array($item->getOrderId(), $usedOrders[$customer->getEmail()])) { continue; } $orderInfo = '<p>Order Id: ' . $order->getIncrementId() . '</p> <p> - Start Date: ' . $order->getStartDatetime() . '</p> <p> - Return Date: ' . $order->getEndDatetime() . '</p>'; $clientListIncoming .= '<li>' . $orderInfo . '</li>'; $nrIncoming++; if (!$isExtended) { $listIncoming .= '<p><a style="font-size:15px" href="' . Mage::getUrl('sales/order/view', array('order_id' => $order->getId())) . '">' . $orderInfo . '</a></p>'; } else { $listIncoming .= '<p><a style="font-size:15px" href="' . Mage::getUrl('payperrentals_front/customer_extendorder', array('order_id' => $order->getId())) . '">' . $orderInfo . '</a></p>'; } $usedOrders[$customer->getEmail()][] = $item->getOrderId(); } foreach ($usedOrders as $email => $orderIds) { foreach ($orderIds as $orderId) { $order = Mage::getModel('sales/order')->load($orderId); $listIncoming .= '<br/><p style="font-style:italic;color:#cccccc;">' . Mage::helper('payperrentals')->__('Products from order:') . ' ' . $order->getIncrementId() . '</p>'; foreach ($order->getAllItems() as $orderItem) { if ($orderItem->getParentItem()) { continue; } //$productQty = intval($orderItem->getQtyInvoiced()); $productName = $orderItem->getName(); $listIncoming .= '<p style="margin-left:20px">' . ' - ' . $productName . '</p>'; } } $reminderPerCustomer[$email][] = $listIncoming; } $clientListIncoming .= '</ul>'; $emailItems = array('nrIncoming' => $nrIncoming, 'clientListIncoming' => $clientListIncoming, 'listIncoming' => $listIncoming, 'reminderPerCustomer' => $reminderPerCustomer, 'customerName' => $customer->getFirstname() . ' ' . $customer->getLastname(), 'reminderdays' => !$isExtended ? Mage::getStoreConfig(self::XML_PATH_REMINDER_DAYS) : Mage::getStoreConfig(self::XML_PATH_EXTENDED_REMINDER_DAYS)); if ($nrIncoming > 0) { if (!$isExtended) { ITwebexperts_Payperrentals_Helper_Emails::sendEmail('return_reminder', $emailItems); } else { ITwebexperts_Payperrentals_Helper_Emails::sendEmail('extend_reminder', $emailItems); } } }