% order_for_delivery is the top-level goal order_for_delivery(Customer_ID,Product,Quantity) :- print('processing order from ',Customer_ID), product_available(Product,Quantity,From_Location), bill_customer(Customer_ID,Product,Quantity,Fee), check_credit(Customer_ID,Fee), pick_inventory(Product,Quantity,From_Location), ship_inventory(Product,Quantity,Customer_ID), print('* order complete *'),!. % product availability check (us only) product_available(Product,Quantity,From_Location) :- product_availability(From_Location,Product,_,Quantity_on_Hand, Quantity_Committed,_), factory_location(From_location,[_,_,_,_,us]), Quantity_Available is Quantity_on_Hand - Quantity_Committed, Quantity_Available >= Quantity, print('product is available (',Quantity_Available,') from ',From_Location),!. % customer billing bill_customer(Customer,Product,Quantity,Fee) :- get_product_price(Customer,Product,Price), Fee is Quantity * Price, compute_sales_tax(Customer,Product,Sales_Tax), compute_discount(Customer,Discount), prepare_bill(Customer,Product,Quantity,Price,Sales_Tax,Discount). % product pricing get_product_price(Customer,Product,Price) :- product_price(Product,Customer,Price,_,_),!. % sales tax - customer and product both non-exempt and location is dc compute_sales_tax(Customer,Product,Sales_Tax) :- customer_location(Customer,[_,_,dc,_,_]), customer_info(Customer,_,non_exempt), product_stax_type(Product,non_exempt), sales_tax(dc,Sales_Tax). compute_sales_tax(Customer,Product,Sales_Tax) :- Sales_Tax = '0%',!. % compute_discount(Customer,Discount). compute_discount(Customer,Discount) :- customer_location(Customer,[_,_,_,_,euro]), euro_discount(Discount),!. compute_discount(Customer,Discount) :- Discount = '0%',!. prepare_bill(Customer,Product,Quantity,Price,Sales_Tax,Discount) :- print('***Customer Billing***'), print('customer ',Customer), print('product ',Product), print('quantity ',Quantity), print('price ',Price), print('sales tax ',Sales_Tax), print('discount ',Discount),!. % check_credit(Customer,Fee). check_credit(Customer_ID,Fee) :- print('credit required: ',Fee), customer_location(Customer_ID,[_,_,_,_,Area]), check_credit_1(Customer_ID,Area). check_credit_1(Customer_ID,us) :- check_customer_inhouse_credit(Customer_ID,us),!. check_credit_1(Customer_ID,euro) :- check_customer_letter_of_credit(Customer_ID,euro),!. check_customer_inhouse_credit(Customer_ID,us) :- print('checking customer inhouse credit for ',Customer_ID),!. check_customer_letter_of_credit(Customer_ID,euro) :- print('checking customer letter of credit for ',Customer_ID),!. pick_inventory(Product,Quantity,From_Location) :- print(From_Location,' pick inventory: ',Product,' quantity: ', Quantity). ship_inventory(Product,Quantity,Customer_ID) :- customer_location(Customer_ID,[_,_,_,_,euro]), print('print customs declaration'), print('ship inventory: ',Product,' to customer ',Customer_ID),!. ship_inventory(Product,Quantity,Customer_ID) :- print('ship inventory: ',Product,' to customer ',Customer_ID). % us sales_tax info sales_tax(dc,'5.75%'). % discount info euro_discount('5%'). % customer_info(Customer_ID,Customer_Type,STax_Type). customer_info(gu,ext_cust,exempt). customer_info(org_a,ext_cust,non_exempt). customer_info(dc_org,ext_cust,non_exempt). % customer_location(Customer_ID,[Street,City,State,Region,Area]) customer_location(gu,['225rsb',wash,dc,east_coast,us]). customer_location(org_a,[_,paris,france,_,euro]). customer_location(dc_org,[_,wash,dc,east_coast,us]). % product_price(Product,Customer,Unit_Price,Unit_Measure,Time_Period). product_price(abc486,gu,1250,each,q1_1994). product_price(abc486,exempt,1500,each,cy_1994). product_price(abc486,_,1750,each,cy_1994). % product_storage_type(Product,Storage_Conditions). product_storage_type(abc486,room_temp). product_storage_type(chem_b,frozen). % product_stax_type(Product,Classification). product_stax_type(abc486,non_exempt). %factory_location(Factory_ID,[Street,City,State,Region,Area]). factory_location(factory1,[_,_,_,_,us]). % product_availability(Factory,Product,Location,Qty_on_Hand,Qty_Comm,Reorder_Pt). product_availability(factory1,abc486,bin01,50,20,15). product_availability(factory1,abc486,bin15,150,100,15). % test specification order_for_delivery(gu,abc486,2)? order_for_delivery(org_a,abc486,1)? order_for_delivery(dc_org,abc486,4)?