Deleting record from database based on an action in a page - mysql

I am making an application for a car dealership. I have a page for stocks and a page for sales. Whenever I make a new entry in sales, I want the corresponding entry to be deleted from the stocks page.
My db for sales is
db.define_table('sales',
Field('customer_name','string'),
Field('village','string'),
Field('mobile_number','integer'),
Field('model','string',required=True,requires=IS_IN_SET(['1035DI','241DI','241DI(P.S.)','245DI','245DI(P.S.)','9000DI','9000DI(P.S)','5245DI','9500DI'])),
Field('engine_number','string'),
Field('chassis_number','string'),
Field('date_of_sale','date'),
Field('sale_price','integer'),
Field('bill_number','integer'),
Field('mode_of_payment','string',requires=IS_IN_SET(['Cash','Cheque']))
)
My db for stock is
db.define_table('stock',
Field('model','string',required=True,requires=IS_IN_SET(['1035DI','241DI','241DI(P.S.)','245DI','245DI(P.S.)','9000DI','9000DI(P.S)','5245DI','9500DI'])),
Field('engine_number','string',required=True),
Field('chassis_number','string',required=True),
Field('invoice_number','integer',required=True),
)
Engine number and chassis number is unique for each entry.

You didn't post any controller code, so I'm just making a simple untested example. I'm assuming you're using SQLFORM, and your sales controller function is just named "sales"
#controller, i.e. default.py
def sales():
form = SQLFORM(db.sales)
if form.process().accepted:
engine_number = form.vars.engine_number
chassis_number = form.vars.chassis_number
db((db.stock.engine_number == engine_number) & (db.stock.chassis_number == chassis_number)).delete()
return dict(form=form)

Related

Function modules to update table bsid (field: cession_kz)

For a certain program I need to update table bsid. The field cession_kz needs to be updated. I've looked for many function modules but none of them fit my needs. Does someone know a best practice to solve this problem?
BSID is a secondary index for BSEG customer items, so updating it directly will lead to database inconsistencies and any update must go via BSEG.
You can use a function module like FI_ITEMS_MASS_CHANGE. This FM updates BSEG by running a BDC for transaction FB02 (Change Document). When a relevant (customer) item is changed in BSEG, the corresponding BSID record is changed as well.
See example code below:
DATA: ls_bseg TYPE bseg,
lt_errdoc TYPE tpit_t_errdoc,
lt_fname TYPE tpit_t_fname,
lt_buztab TYPE tpit_t_buztab.
* Field name to be changed
APPEND 'CESSION_KZ' TO lt_fname.
* New field value
ls_bseg-cession_kz = 'AB'.
* Selection of items to be changed
* Only select customer items to avoid problems in batch input
SELECT bukrs belnr gjahr buzei koart umskz bschl mwart mwskz
FROM bseg
INTO CORRESPONDING FIELDS OF TABLE lt_buztab
WHERE belnr = '1400000000' AND
bukrs = '1000' AND
koart = 'D'. "Customers
CALL FUNCTION 'FI_ITEMS_MASS_CHANGE'
EXPORTING
s_bseg = ls_bseg
IMPORTING
errtab = lt_errdoc[]
TABLES
it_buztab = lt_buztab
it_fldtab = lt_fname
EXCEPTIONS
bdc_errors = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Make sure you allow changes in maintenance view V_TBAER with transaction SM30 or through customizing:
Financial Accounting → Financial Accounting Global Settings → Document → Line Item → Document Change Rules, Line Item.
Note:
Pledging indicators should be defined for all company codes passed to the FM:
Financial Accounting → Accouts Receivable and Accounts Payable → Customer Account → Master Data → Preperation for creating master data → Define Accounts Receivable Pledging Indicator.
If not, the field will not be available for the batch input and the FM will result in an error.

How to pass the values from accessed database to the new formed database?

My project is to create an emenu.For this I have created a database in phpmyadmin.The menu has been accessed by using code below.And now I want to send that menu item to a new database(that has been already created) on clicking the button "add to cart".I cannot seem to find a way to pass the value as a variable.i.e.name,price in this code. This is my code:
class Appetizers(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
self.controller=controller
def insdb():
cro=mysql.connector.connect(user='k***',password='***',host='******',database='newdb')
mycursor=cro.cursor()
mycursor.execute("""INSERT INTO order_frm_client(name,quantity,price) VALUES(name,2,price)""" )
cro.commit()
conn=mysql.connector.connect(user='k***',password='***',host='*****',database='menu')
mycursor=conn.cursor()
mycursor.execute("SELECT * FROM APPETIZERS")
results=mycursor.fetchall()
yo=50
for row in results:
id=row[0]
name=row[1]
price=row[3]
listBox = Listbox(self, height=1,width=40,highlightcolor="red")
listBox.place(x=100,y=yo)
listBox.insert(END,name)
listBox1 = Listbox(self, height=1,width=10,highlightcolor="red")
listBox1.place(x=350,y=yo)
listBox1.insert(END,price)
spin=Spinbox(self, from_=0, to=10, width=10).place(x=420,y=yo)
button=Button(self, text='Add to Cart',width=4, command=insdb(name,price))
button.place(x=500,y=yo)
yo=yo+30

How to put flat rate before subtotal at checkout time in magento

I want to put flat rate before subtotal which is by default below to subtotal.
How to add an additional Fee or Discount, or any kind of charge to order total of the magento checkout process
In a typical order, the order totals usually comprises of Sub Total, Shipping Cost, Taxes, Discount, based on these values the total order grand total is calculated.
This extra fee which we are adding to the total would reflect in the
Checkout Page Order Total,
Cart Page Order Total,
My Account Order View Page,
Print Order PDF,
Order EMails,
Admin Order View/Email/PDF,
Admin Invoice View/Email/PDF,
Admin Credit Memo View/Email/PDF.
Checkout Page Total Order Total Basics
We will see how to add the totals only to the checkout page. All the totals line items that show up the checkout page come from files located at folder Mage\Sales\Model\Quote\Address\Total.
In magento before order is placed all order data is stored in a quote object and after order is placed it gets transferred to the order object. The quote totals follow the collector pattern and we can add collector as many collector classes. To add collector to the quote object in our config.xml we add the lines
<global>
<sales>
<quote>
<totals>
<fee>
<class>fee/sales_quote_address_total_fee</class>
</fee>
</totals>
</quote>
</sales>
This means whenever the totals are calculated for a quote, it will also call this class.
All collectors are called from the collectTotals() function in the Quote Model.
In our collector class we put in the code
<?php class Excellence_Fee_Model_Sales_Quote_Address_Total_Fee
extends Mage_Sales_Model_Quote_Address_Total_Abstract{
protected $_code = 'fee';
public function collect(Mage_Sales_Model_Quote_Address $address)
{
parent::collect($address);
$this->_setAmount(0);
$this->_setBaseAmount(0);
$items = $this->_getAddressItems($address);
if (!count($items)) {
return $this; //this makes only address type shipping to come through
}
$quote = $address->getQuote();
if(Excellence_Fee_Model_Fee::canApply($address)){ //your business logic
$exist_amount = $quote->getFeeAmount();
$fee = Excellence_Fee_Model_Fee::getFee();
$balance = $fee - $exist_amount;
$address->setFeeAmount($balance);
$address->setBaseFeeAmount($balance);
$quote->setFeeAmount($balance);
$address->setGrandTotal($address->getGrandTotal() + $address->getFeeAmount());
$address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseFeeAmount());
}
}
public function fetch(Mage_Sales_Model_Quote_Address $address)
{
$amt = $address->getFeeAmount();
$address->addTotal(array(
'code'=>$this->getCode(),
'title'=>Mage::helper('fee')->__('Fee'),
'value'=> $amt
));
return $this;
}
}
Here we are using two fields fee_amount and base_fee_amount, which contain our fee amount. We will have to see save these two fields to database, so in our module installer file we add this code
ALTER TABLE `".$this->getTable('sales/quote_address')."` ADD `fee_amount` DECIMAL( 10, 2 ) NOT NULL;
ALTER TABLE `".$this->getTable('sales/quote_address')."` ADD `base_fee_amount` DECIMAL( 10, 2 ) NOT NULL;
Order Page
Till now, all code written has been done only for the quote object. But after order is placed, we need to transfer all information to the order object. As you would have seen above we are using two fields fee_amount and base_fee_amount, we now need to store these two fields in the order table as well. To do all the above we need to do two things. First in the config.xml file add this code inside the global tab,
<fieldsets>
<sales_convert_quote_address>
<fee_amount><to_order>*</to_order></fee_amount>
<base_fee_amount><to_order>*</to_order></base_fee_amount>
</sales_convert_quote_address>
</fieldsets>
in our module install file
ALTER TABLE `".$this->getTable('sales/order')."` ADD `fee_amount` DECIMAL( 10, 2 ) NOT NULL;
ALTER TABLE `".$this->getTable('sales/order')."` ADD `base_fee_amount` DECIMAL( 10, 2 ) NOT NULL;

VBA code to analyze a HTML table based off certain conditions

So I need to screen scrape data off a website and return it to a spreadsheet based off if a charge amount matched as well the date was the most recent in the table. If there was simply one line in the table, the macro pulls that accordingly. So most of the code is good, I am connected to the website, pulling everything effectively. Where I am struggling is getting the logic to work where the two amounts match as well as the date being the most recent in the HTML table.
I guess what my question is how do I loop through Item(5) the column of that table and specify it to choose the most recent date, also setting the value so that it only finds the one equal to the charge amount. I only want a one to one match. I am new to this so if anyone wants to help me I would greatly appreciate it.
Set IHEC = iHTMLDoc.getElementsByTagName("TR")
If IHEC.Length > 2 Then
For index = 0 to IHEC.Length - 1
Set IHEC_TD = IHEC.Item(index).getElementsByTagName("TD")
Do Until IHEC.Length <2 Or index = IHEC.Length - 1
If IHEC.TD.Item(3).innerText = myBilledAmount Then
myItem1 = IHEC_TDItem(0).innerText
myItem2 = IHEC_TDItem(1).innerText
myItem3 = IHEC_TDItem(2).innerText
myItem4 = IHEC_TDItem(3).innerText
myItem5 = IHEC_TDItem(4).innerText
myItem6 = IHEC_TDItem(5).innerText
myItem7 = IHEC_TDItem(6).innerText
myItem8 = IHEC_TDItem(7).innerText
myItem9 = IHEC_TDItem(8).innerText
End If
End If
Loop
Next Index

BigCommerce Stencil - Product Variant Stock Levels

A client wants to set up A/B testing on the Product Detail Page related to the stock_level of a product's variants. Once the user selects their options, if the quantity is less than 5, I'd show something like "Hurry, only 3 more in stock"...
I believe I have the correct Inventory settings enabled, because I can retrieve the stock_level of a product without options.
Has anyone had success pulling variant SKU stock_levels in stencil?
Thanks
This can be done using javascript in the assets/js/theme/common/product-details.js file. On initial page load and each time a product option is changed, there is a function updateView(data) that is called. The data parameter contains all the info you need for the selected variation.
Starting on line 285, replace this:
updateView(data) {
const viewModel = this.getViewModel(this.$scope);
this.showMessageBox(data.stock_message || data.purchasing_message);
with this:
updateView(data) {
const viewModel = this.getViewModel(this.$scope);
if(data.stock < "5") {
data.stock_message = "Hurry, only " + data.stock + " left!";
}
this.showMessageBox(data.stock_message || data.purchasing_message);