Subversion Repositories SmartDukaan

Rev

Rev 6857 | Rev 7410 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

namespace java in.shop2020.purchase
namespace py shop2020.thriftpy.purchase

include "GenericService.thrift"

struct Supplier {
    1:i64 id,
    2:string name,
    3:string phone,
    4:string fax,
    5:string tin,
    6:string pan,
    7:string headName,
    8:string headDesignation,
    9:string headEmail,
    10:string contactName,
    11:string contactPhone,
    12:string contactFax,
    13:string contactEmail,
    14:string registeredAddress,
    15:string communicationAddress
}

struct LineItem {
    1:i64 orderId,
    2:i64 itemId,
    3:string productGroup,
    4:string brand,
    5:string modelNumber,
    6:string modelName,
    7:string color,
    8:string itemNumber,
    9:double quantity,
    10:double unfulfilledQuantity,
    11:i64 createdAt,
    12:double unitPrice,
    13:bool fulfilled,
    14:i64 codCount
    15:i64 availableQuantity
    16:i64 reservedQuantity
    17:double avgSales
    18:i64 minStockLevel
    19:i64 numberOfDaysStock
    20:i64 suggestedQuantity
    21:i64 numberOfDaysInStock
    22:string lastXdaysSale
    23:i64 previouslyOrderedQty
}

enum POStatus {
    INIT = 0,                   //Just created.
    READY = 1,                  //Posted for fulfillment.
    PARTIALLY_FULFILLED = 2,    //Partially fulfullied. Possible to accept purchases against it.
    PRECLOSED = 3,              //PO was partially fulfilled and the supplier has clarified that he can't supply the remaining items. 
    CLOSED = 4                  //PO was completely fulfilled.
}

enum POType {
    REAL = 1,                   //PO created manually
    VIRTUAL = 2                     //Virtual PO generated automatically for Ours_External Billing
}

enum PurchaseReturnType {
    REAL = 1,                   //Purchase Returns where stock is returned to Vendor
    VIRTUAL = 2                     //Virtual Purchase Return associated with Sale Returns for OursExternal Billing
}

struct PurchaseOrder {
    1:i64 id,
    2:string poNumber,
    3:list<LineItem> lineitems,
    4:i64 supplierId,
    5:i64 warehouseId,
    6:POStatus status,
    7:i64 createdAt,
    8:i64 updatedAt,
    9:double totalCost,
    10:double freightCharges,
    11:double realizedCost,
    12:double realizedFreightCharges,
    13:POType type
}

struct Purchase {
    1:i64 id,
    2:i64 poId,
    3:string invoiceNumber,
    4:i64 receivedOn,
    5:double freightCharges
}

struct PurchaseReturn {
    1:i64 id,
    2:i64 vendorId,
    3:i64 amount,
    4:i64 returnTimestamp,
    5:bool isSettled,
    6:PurchaseReturnType type
}

struct Invoice {
    1:i64 id,
    2:string invoiceNumber,
    3:i64 date,
    4:i64 numItems,
    5:string receivedFrom,
    6:i64 supplierId
}

exception PurchaseServiceException {
    1:GenericService.ExceptionType exceptionType,
    2:string message
}

service PurchaseService extends GenericService.GenericService {
    /**
    Creates a purchase order based on the data in the given purchase order object.
    This method populates a nummber of missing fields 
    */
    i64 createPurchaseOrder(1:PurchaseOrder purchaseOrder) throws (1:PurchaseServiceException e),
    
    /**
    Returns the purchase order with the given id. Throws an exception if there is no such purchase order.
    */
    PurchaseOrder getPurchaseOrder(1:i64 id) throws (1:PurchaseServiceException e),

    /**
    Returns a list of all the purchase orders in the given state
    */
    list<PurchaseOrder> getAllPurchaseOrders(1:POStatus status) throws (1:PurchaseServiceException e),
    
    /**
    Returns the supplier with the given order id. Throws an exception if there is no such supplier.
    */
    Supplier getSupplier(1:i64 id) throws (1:PurchaseServiceException e),
    
    /**
    Creates a purchase for the given purchase order.
    Throws an exception if no more purchases are allowed against the given purchase order.
    */
    i64 startPurchase(1:i64 purchaseOrderId, 2:string invoiceNumber, 3:double freightCharges) throws (1:PurchaseServiceException e),
    
    /**
    Marks a purchase as complete and updates the receivedOn time.
    Throws an exception if no such purchase exists.
    */
    i64 closePurchase(1:i64 purchaseId) throws (1:PurchaseServiceException e),
    
    /**
    Returns all open or closed purchases for the given purchase order. Throws an exception if no such purchase order exists
    */
    list<Purchase> getAllPurchases(1:i64 purchaseOrderId, 2:bool open) throws (1:PurchaseServiceException e),
    
    /**
    Returns all purchases for the given purchase order. Throws an exception if no such purchase order exists
    */
    list<Purchase> getPurchasesForPO(1:i64 purchaseOrderId) throws (1:PurchaseServiceException e),

    /**
     * Returns the purchase order object for a given purchase
     */
    PurchaseOrder getPurchaseOrderForPurchase(1:i64 purchaseId);

    /**
     * Creates purchase order objects from pending orders
     */
    list<PurchaseOrder> getPendingPurchaseOrders(1:i64 warehouseId) throws (1:PurchaseServiceException e);

    /**
     * Returns all the valid suppliers
     */
    list<Supplier> getSuppliers() throws (1:PurchaseServiceException e);

    /**
     * Fulfills a given purchase order with an item.
     */
    void fulfillPO(1:i64 purchaseOrderId, 2:i64 itemId, 3:i64 quantity) throws (1:PurchaseServiceException e);

    /**
     * Amends a PO as per the new lineitems passed 
     */
    void updatePurchaseOrder(1:PurchaseOrder purchaseOrder) throws (1:PurchaseServiceException e),

    /**
     * Fulfills a given purchase id with an item and its quantity.
     */
    void unFulfillPO(1:i64 purchaseId, 2:i64 itemId, 3:i64 quantity) throws (1:PurchaseServiceException e);
    
    /**
     * Fetches all invoices after a given date
     */
    list<Invoice> getInvoices(1:i64 date);

    /**
     * Creates an invoice object
     */
    void createInvoice(1:Invoice invoice) throws (1:PurchaseServiceException e);
    
    /**
     * Creates a supplier 
     */
    Supplier addSupplier(1:Supplier supplier);

    /**
     * Updates a supplier 
     */
    void updateSupplier(1:Supplier supplier);
    
    /**
     * Create a new Purchase Return
    */
        i64 createPurchaseReturn(1:PurchaseReturn purchaseReturn);
    
    /**
     * Create a new Purchase Return
    */
    void settlePurchaseReturn(1:i64 id);
    
    /**
     * Create a new Purchase Return
    */
    list<PurchaseReturn> getUnsettledPurchaseReturns();
    
    /**
     * Get invoice with given supplierId and invoiceNumber
    */
    list<PurchaseReturn> getInvoice(1:string invoiceNumber, 2:i64 supplierId);
    
    /**
     * Inserts new Invoice/LineItem/Purchase Entries for Billed Product done through Our External Billing
    **/
    i64 createPurchaseForOurExtBilling(1:string invoiceNumber, 2:double unitPrice, 3:i64 itemId);
    
    void fulfillPOForExtBilling(1:i64 itemId, 2:i64 quantity);
    
    
    
}