Пример #1
0
/*******************************************************************
 * fm_pymt_pol_collect_clear_pending():
 *******************************************************************/
static void
fm_pymt_pol_collect_clear_pending(
	pin_flist_t	*r_flistp,
	pin_decimal_t	*amount,
	char		*descr,
	pin_errbuf_t	*ebufp)
{
	pin_flist_t	*flistp = NULL;
	char		*action;
	int		count;

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Don't bother with zero amounts.
	 ***********************************************************/
	if (pbo_decimal_sign(amount, ebufp) == 0) {
		return;
		/*****/
	}

	/***********************************************************
	 * What elemid to add.
	 ***********************************************************/
	count = PIN_FLIST_ELEM_COUNT(r_flistp, PIN_FLD_ACTIVITIES, ebufp);

	/***********************************************************
	 * Add our element.
	 ***********************************************************/
	flistp = PIN_FLIST_ELEM_ADD(r_flistp, PIN_FLD_ACTIVITIES, count, ebufp);

	/***********************************************************
	 * Fill in our values.
	 ***********************************************************/
	action = "clear_pending";
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_ACTION, (void *)action, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_AMOUNT, (void *)amount, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void *)descr, ebufp);

	return;
}
Пример #2
0
/*******************************************************************
 * fm_pymt_pol_collect_set_status():
 *******************************************************************/
static void
fm_pymt_pol_collect_set_status(
	pin_flist_t		*r_flistp,
	pin_status_t		status,
	int			flags,
	char			*descr,
	pin_errbuf_t		*ebufp)
{
	pin_flist_t		*flistp = NULL;
	char			*action;
	int			count;

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * What elemid to add.
	 ***********************************************************/
	count = PIN_FLIST_ELEM_COUNT(r_flistp, PIN_FLD_ACTIVITIES, ebufp);

	/***********************************************************
	 * Add our element.
	 ***********************************************************/
	flistp = PIN_FLIST_ELEM_ADD(r_flistp, PIN_FLD_ACTIVITIES, count, ebufp);

	/***********************************************************
	 * Fill in our values.
	 ***********************************************************/
	action = "set_status";
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_ACTION, (void *)action, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_STATUS, (void *)&status, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_STATUS_FLAGS, (void *)&flags, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void *)descr, ebufp);

	return;
}
/*
 * Search for a brand name in the whole system.
 */
static void
fm_cust_pol_is_brandname_unique_global(
	pcm_context_t		*ctxp,
	poid_t			*poidp,
	char			*namep,
	pin_flist_t		**r_flistpp,
	pin_errbuf_t		*ebufp)
{
	pin_flist_t		*flistp = (pin_flist_t *)NULL;
	pin_flist_t		*rlistp = (pin_flist_t *)NULL;
	pin_flist_t		*sublistp;
	poid_t			*search_poidp;
	int32			int_val;
	int32			cred;
	pin_account_type_t	brand_type = PIN_ACCOUNT_TYPE_BRAND;
	pin_cookie_t		cookie = (pin_cookie_t)NULL;

	/*
	 * If there are pending errors, then short circuit immediately
	 */
        if (PIN_ERR_IS_ERR(ebufp))
                return;
        PIN_ERR_CLEAR_ERR(ebufp);

	/*
	 * Create search flist to try to figure out if someone brand already
	 * has this name.
	 *
	 * NOTE: we really only need to search for accounts that are of type
	 * 'brand' and of a particular name. Unfortunately, neither of these
	 * fields are indexed by default, thus causing a performance problem.
	 *
	 * To get around this, we'll turn this into a complex search. We know
	 * that brands are the parent of a /group/billing object, so glue that
	 * in as well. That should be indexed...
	 */
	flistp = PIN_FLIST_CREATE(ebufp);
	search_poidp = PIN_POID_CREATE(PIN_POID_GET_DB(poidp), "/search", -1,
		ebufp);
	PIN_FLIST_FLD_PUT(flistp, PIN_FLD_POID, (void *)search_poidp, ebufp);
	int_val = SRCH_DISTINCT;
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_FLAGS, (void *)&int_val, ebufp);

	PIN_FLIST_FLD_SET(flistp, PIN_FLD_TEMPLATE, 
		(void *)"select X from /account 1, /group 2 where 1.F1 = V1 "
		"AND 1.F2 = V2 AND 1.F3 = 2.F4 AND 1.F5 != V5 ",
		ebufp);
	PIN_FLIST_ELEM_SET(flistp, NULL, PIN_FLD_RESULTS, 0, ebufp);

	/*
	 * Arg 1 is the type of the account; only interested in brand accounts
	 */
	sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 1, ebufp);
	PIN_FLIST_FLD_SET(sublistp, PIN_FLD_ACCOUNT_TYPE, (void *)&brand_type,
		ebufp);

	/*
	 * Arg 2 is the name of the brand.
	 */
	sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 2, ebufp);
	PIN_FLIST_FLD_SET(sublistp, PIN_FLD_NAME, (void *)namep, ebufp);

	/*
	 * Arg 3 -- POID of account
	 */
	sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 3, ebufp);
	PIN_FLIST_FLD_PUT(sublistp, PIN_FLD_POID, NULL, ebufp);

	/*
	 * Arg 4 -- Parent of the group
	 */
	sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 4, ebufp);
	PIN_FLIST_FLD_PUT(sublistp, PIN_FLD_PARENT, NULL, ebufp);

        /*
         * Arg 5 -- POID of current account
         */
        sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 5, ebufp);
        PIN_FLIST_FLD_SET(sublistp, PIN_FLD_POID, poidp, ebufp);

	/*
	 * Ready to search! Temporarily suspend search to ensure that
	 * all brands are traversed.
	 */
	cred = CM_FM_BEGIN_OVERRIDE_SCOPE(CM_CRED_SCOPE_OVERRIDE_ROOT);
	PCM_OP(ctxp, PCM_OP_GLOBAL_SEARCH, PCM_OPFLG_COUNT_ONLY, 
		flistp, &rlistp, ebufp);
	CM_FM_END_OVERRIDE_SCOPE(cred);

	/* 
	 * See if there is a brand out there right now that already has
	 * this name. If so, flag it as an error.
	 */
	PIN_FLIST_ELEM_GET_NEXT(rlistp, PIN_FLD_RESULTS, &int_val, 1, 
		&cookie, ebufp);
	if(int_val > 0) {
		*r_flistpp = PIN_FLIST_CREATE(ebufp);
		PIN_FLIST_FLD_SET(*r_flistpp, PIN_FLD_POID, (void *)poidp, 
			ebufp);
		fm_cust_pol_valid_add_fail(*r_flistpp, 
			PIN_FLD_NAME,
			0,
			PIN_CUST_VAL_ERR_DUPE,
			PIN_CUST_DUPE_VALUE_ERR_MSG,
			(void *)namep, ebufp);

		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_DUPLICATE, PIN_FLD_NAME, 
			0, 0);
	}

	/*
	 * Cleanup and return
	 */
	PIN_FLIST_DESTROY_EX(&flistp, NULL);
	PIN_FLIST_DESTROY_EX(&rlistp, NULL);
}
static void
fm_get_meta_field(
	pcm_context_t           *ctxp,
        pin_flist_t             *in_flistp,
        pin_flist_t             **out_flistpp,
        pin_errbuf_t            *ebufp)
{
	pin_flist_t     *keys_flistp = NULL;
        pin_flist_t     *search_flistp = NULL;
        pin_flist_t     *flistp = NULL; 
        poid_t          *s_pdp = NULL; 
        poid_t          *bi_pdp = NULL; 
        int64           database = 0;
        int32           sflags = 256;
        int32           result = PIN_BOOLEAN_FALSE;
        void            *vp = NULL;
        pin_decimal_t   *zero_decimal =  pin_decimal("0.0", ebufp);
	pin_flist_t	*r_flistp = NULL;
	char                    *name = NULL;
	char                    *class_name = NULL;
	char                    *default_value;
	int32           count = 0;
	int32           cnt_flds = 0;
	int32                   elemid = 1;
	pin_errbuf_t            any_field_ebuf;
        pin_cookie_t            cookie = NULL;
        pin_fld_num_t           field = 0;
        int32                   rec_id = 0;
	void            *type = NULL;

        if (PIN_ERR_IS_ERR(ebufp)) {
                return;
        }
        PIN_ERR_CLEAR_ERR(ebufp);
	PIN_ERR_CLEAR_ERR(&any_field_ebuf);
	
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "fm_get_meta_field input flistp", in_flistp);
	bi_pdp = (poid_t *) PIN_FLIST_FLD_GET(in_flistp,
                                PIN_FLD_POID,0, ebufp);

	count = PIN_FLIST_ELEM_COUNT (in_flistp,
                        PIN_FLD_KEYS, ebufp);
	if (count == 0)
        {

                 pin_set_err(ebufp, PIN_ERRLOC_FM,
                        PIN_ERRCLASS_SYSTEM_DETERMINATE,
                        PIN_ERR_BAD_OPCODE, 0, 0, count);
                PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
                        "op_get_meta_field search flistp", ebufp);

                *out_flistpp = NULL;
                return;
        }

	else {
	keys_flistp = PIN_FLIST_ELEM_GET (in_flistp, PIN_FLD_KEYS,
                PIN_ELEMID_ANY, 0, ebufp);
	while (PIN_FLIST_ANY_GET_NEXT(keys_flistp, &field,
                                &rec_id, &cookie, &any_field_ebuf) != NULL ){
        cnt_flds = cnt_flds + 1;
	if (field == PIN_FLD_NAME){
 	name = (char *)PIN_FLIST_FLD_GET(keys_flistp, PIN_FLD_NAME, 1, ebufp);
	}
	if (field == PIN_FLD_CLASS_NAME){
       class_name = PIN_FLIST_FLD_GET(keys_flistp, PIN_FLD_CLASS_NAME, 0, ebufp );
	}
	if (field == PIN_FLD_TYPE){
	type = PIN_FLIST_FLD_GET(keys_flistp, PIN_FLD_TYPE, 0, ebufp );			
	}
	}
	if ( cnt_flds == 1)
        {
        vp = (void *)"select X from /metafield where F1 = V1 ";
        }
        if ( cnt_flds == 2)
        {
        vp = (void *)"select X from /metafield where F1 = V1 and F2 = V2 ";
        }
        if ( cnt_flds == 3)
        {
        vp = (void *)"select X from /metafield where F1 = V1 and F2 = V2 and F3 = V3 ";
        }

	 /*********************************************************
         * Create the search flist to search in the item objects
         *********************************************************/
        search_flistp = PIN_FLIST_CREATE(ebufp);
        database = PIN_POID_GET_DB(bi_pdp);
        s_pdp = PIN_POID_CREATE(database, "/search", -1, ebufp);
        PIN_FLIST_FLD_PUT(search_flistp, PIN_FLD_POID, (void *)s_pdp, ebufp);
       /******************************************************************
         * Set the search template.
         ******************************************************************/
        PIN_FLIST_FLD_SET(search_flistp, PIN_FLD_TEMPLATE, vp, ebufp);
        PIN_FLIST_FLD_SET(search_flistp, PIN_FLD_FLAGS, (void *)&sflags, ebufp);

	/*********************************************************
         * Add the search arguments.
         *********************************************************/
	if (name != NULL) {
        flistp = PIN_FLIST_ELEM_ADD(search_flistp, PIN_FLD_ARGS, elemid++, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_NAME, name, ebufp);
	}

        /*********************************************************
         * Add the search arguments.
         *********************************************************/
	if (class_name != NULL) {
        flistp = PIN_FLIST_ELEM_ADD(search_flistp, PIN_FLD_ARGS, elemid++, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_CLASS_NAME, class_name, ebufp);
        }
	
	/*********************************************************
         * Add the search arguments.
         *********************************************************/
        if (type != NULL) {
        flistp = PIN_FLIST_ELEM_ADD(search_flistp, PIN_FLD_ARGS, elemid++, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE, type, ebufp);
        }


        /*********************************************************
         * Add the result array for the search.
         *********************************************************/

        flistp = PIN_FLIST_ELEM_ADD(search_flistp, PIN_FLD_RESULTS, 0, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE,(void *)NULL, ebufp);
        
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "op_get_meta_field search flistp", search_flistp);  

	 PCM_OP(ctxp, PCM_OP_SEARCH, 0, search_flistp, out_flistpp, ebufp);

	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "op_get_meta_field search flistp", *out_flistpp);
	}
	     
 	}
/*
 * Search for a brand name within a brand.
 */
static void
fm_cust_pol_is_brandname_unique_within_brand(
	pcm_context_t		*ctxp,
	poid_t			*poidp,
	char			*namep,
	pin_flist_t		**r_flistpp,
	pin_errbuf_t		*ebufp)
{
	pin_flist_t		*flistp = (pin_flist_t *)NULL;
	pin_flist_t		*rlistp = (pin_flist_t *)NULL;
	pin_flist_t		*sublistp;
	poid_t			*search_poidp;
	int32			int_val;
	int32			cred;
	pin_account_type_t	brand_type = PIN_ACCOUNT_TYPE_BRAND;
	pin_cookie_t		cookie = (pin_cookie_t)NULL;
	pin_flist_t             *b_flistp = NULL;
	pin_flist_t             *t_flistp = NULL;
	poid_t                  *b_pdp = NULL;
	poid_t                  *g_pdp = NULL;
	poid_t                  *rootp = NULL;
	int32                   elemid = 0;
	int			under_host = PIN_BOOLEAN_FALSE;
	void			*vp = NULL;

	/*
	 * If there are pending errors, then short circuit immediately
	 */
        if (PIN_ERR_IS_ERR(ebufp))
                return;
        PIN_ERR_CLEAR_ERR(ebufp);

	fm_utils_lineage_get_brand_hierarchy(ctxp, poidp, &b_flistp, ebufp);
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_cust_pol_is_brandname_unique_within_brand() : "
			"Call to get brand hierarchy failed ",
			ebufp);
	 	PIN_FLIST_DESTROY_EX (&b_flistp, NULL);
		fm_cust_pol_read_err_return_list(poidp, namep, r_flistpp,
			ebufp);
                goto cleanup;
        }

        PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"Got brand hierarchy.  Return flist :", b_flistp);

	t_flistp = PIN_FLIST_ELEM_GET_NEXT(b_flistp,
		PIN_FLD_RESULTS, &elemid, 1, &cookie, ebufp);
	if (PIN_ERR_IS_ERR(ebufp) || t_flistp == (pin_flist_t *)NULL) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_cust_pol_is_brandname_unique_within_brand() : "
			"Call to get first brand failed ",
			ebufp);
		PIN_FLIST_DESTROY_EX (&b_flistp, NULL);
		fm_cust_pol_read_err_return_list(poidp, namep, r_flistpp,
			ebufp);
                goto cleanup;
	}
	
	/********************************************
	 * Get the first brand object from hierarchy
	 ********************************************/
	b_pdp = PIN_FLIST_FLD_GET(t_flistp, PIN_FLD_BRAND_OBJ, 0, ebufp);

	/***************************************************************
	 * During the brand creation, the first brand object from the
	 * the hierarchy is the parent brand. But, for an existing 
	 * brand, the first object is self, the next one in hierarchy 
	 * is the parent brand.
	 ***************************************************************/
	if (!PIN_POID_COMPARE(b_pdp, poidp, 0, ebufp)) {
		PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "first brand is self");
		t_flistp = PIN_FLIST_ELEM_GET_NEXT(b_flistp,
			PIN_FLD_RESULTS, &elemid, 1, &cookie, ebufp);
		if (PIN_ERR_IS_ERR(ebufp) || t_flistp == (pin_flist_t *)NULL) {
			PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_cust_pol_is_brandname_unique_within_brand() : "
			"Call to get second brand failed ",
			ebufp);
			PIN_FLIST_DESTROY_EX (&b_flistp, NULL);
			fm_cust_pol_read_err_return_list(poidp, namep, 	
				r_flistpp, ebufp);
                	goto cleanup;
		}
	 	/* Get the parent brand object */
		b_pdp = PIN_FLIST_FLD_GET(t_flistp, PIN_FLD_BRAND_OBJ, 
			0, ebufp);
	}
	else {
		PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "first brand is parent");
	}

	PIN_ERR_LOG_POID(PIN_ERR_LEVEL_DEBUG, "parent brand = ", b_pdp);

	/***************************************************************
	 * Check to see if we are creating brand under brandhost
	 ***************************************************************/
	rootp = PIN_POID_CREATE(PIN_POID_GET_DB(poidp), "/account", 1, ebufp);
	if (!PIN_POID_COMPARE(b_pdp, rootp, 0, ebufp)) {
		under_host = PIN_BOOLEAN_TRUE;  /* creating brand under 
						   brandhost */
	}
	else {	/* creating sub-brand under a brand */
		/* get the group_obj_id0 for the parent brand */
		cred = CM_FM_BEGIN_OVERRIDE_SCOPE(CM_CRED_SCOPE_OVERRIDE_ROOT); 
		g_pdp = fm_utils_lineage_get_billing_group_by_parent(ctxp, 
			b_pdp, ebufp);
		CM_FM_END_OVERRIDE_SCOPE(cred); 
		if (PIN_ERR_IS_ERR(ebufp) || g_pdp == (poid_t*)NULL) {
			PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_cust_pol_is_brandname_unique_within_brand() : "
			"Call to get parent group failed ",
			ebufp);
			PIN_POID_DESTROY(rootp, NULL);
			PIN_FLIST_DESTROY_EX (&b_flistp, NULL);
			fm_cust_pol_read_err_return_list(poidp, namep, 
				r_flistpp, ebufp);
                	goto cleanup;
		}
	}
	PIN_POID_DESTROY(rootp, NULL);
	PIN_FLIST_DESTROY_EX (&b_flistp, NULL);
	
	/*
	 * Create search flist to try to figure out if someother brand already
	 * has this name within the parent brand.
	 */
	flistp = PIN_FLIST_CREATE(ebufp);
	search_poidp = PIN_POID_CREATE(PIN_POID_GET_DB(poidp), "/search", -1,
		ebufp);
	PIN_FLIST_FLD_PUT(flistp, PIN_FLD_POID, (void *)search_poidp, ebufp);
	int_val = SRCH_DISTINCT;
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_FLAGS, (void *)&int_val, ebufp);

	/***************************************************************
	 * We need different search templates for checking duplicate
	 * brandnames under the brandhost or another brand.
	 * The brandhost doesnot have an entry in the /group/billing
	 * storable class. The only way we can get the names of the 
	 * existing brands under the brandhost is to check the lineage
	 * tag. Arguments 1 to 3 are the same for both search templates,
	 * but arguments 4 & 5 are different. 
	 ***************************************************************/
	if (under_host == PIN_BOOLEAN_FALSE) {  
		/* creating sub-brands under a brand */
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_TEMPLATE, 
			(void *)TEMPLATE_UNIQUE_UNDER_BRAND, ebufp);
	}
	else {                   /* creating brand under brandhost */
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_TEMPLATE, 
			(void *)TEMPLATE_UNIQUE_UNDER_BRANDHOST, ebufp);
	}
	PIN_FLIST_ELEM_SET(flistp, NULL, PIN_FLD_RESULTS, 0, ebufp);

	/*
	 * Arg 1 is the type of the account; only interested in brand accounts
	 */
	sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 1, ebufp);
	PIN_FLIST_FLD_SET(sublistp, PIN_FLD_ACCOUNT_TYPE, (void *)&brand_type,
		ebufp);

	/*
	 * Arg 2 is the name of the brand.
	 */
	sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 2, ebufp);
	PIN_FLIST_FLD_SET(sublistp, PIN_FLD_NAME, (void *)namep, ebufp);

	/*
	 * Arg 3 -- POID of account
	 */
	sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 3, ebufp);
	PIN_FLIST_FLD_PUT(sublistp, PIN_FLD_POID, NULL, ebufp);

	if (under_host == PIN_BOOLEAN_FALSE) {  
		/* creating sub-brands under a brand */
		/*
	 	 * Arg 4 -- OBJECT_ID of members from /group/billing 
	 	 */
		sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 4, ebufp);
		sublistp = PIN_FLIST_ELEM_ADD(sublistp, PIN_FLD_MEMBERS, 
			PIN_ELEMID_ANY, ebufp);
        	PIN_FLIST_FLD_PUT(sublistp, PIN_FLD_OBJECT, (void *)NULL, 
			ebufp);

		/*
	 	 * Arg 5 -- POID of the group
	 	 */
		sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 5, ebufp);
		PIN_FLIST_FLD_SET(sublistp, PIN_FLD_POID, (void *)g_pdp, ebufp);
	}
	else {                   /* creating brand under brandhost */
		/*
	 	 * Arg 4 -- Parent of the group
	 	 */
		sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 4, ebufp);
		PIN_FLIST_FLD_PUT(sublistp, PIN_FLD_PARENT, NULL, ebufp);

		/*
	 	 * Arg 5 -- LINEAGE of account
	 	 */
		/* accounts under brandhost have only one ":" in their
		   lineage tag. We want to exclude others. */

		vp = (void *)"%:%:%";	
		sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 5, ebufp);
		PIN_FLIST_FLD_SET(sublistp, PIN_FLD_LINEAGE, vp, ebufp);
	}

        /*
         * Arg 6 -- POID of current account
         */
        sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 6, ebufp);
        PIN_FLIST_FLD_SET(sublistp, PIN_FLD_POID, poidp, ebufp);

	/*
	 * For completeness, dump the input flist if debugging is enabled.
	 */
        PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
                          "fm_cust_pol_is_brandname_unique_within_brand search input flist:",
                          flistp);

	/*
	 * Ready to search! Temporarily suspend search to ensure that
	 * all brands are traversed.
	 */
	cred = CM_FM_BEGIN_OVERRIDE_SCOPE(CM_CRED_SCOPE_OVERRIDE_ROOT);
	PCM_OP(ctxp, PCM_OP_GLOBAL_SEARCH, PCM_OPFLG_COUNT_ONLY, 
		flistp, &rlistp, ebufp);
	CM_FM_END_OVERRIDE_SCOPE(cred);

	/*
	 * For completeness, dump the results flist if debugging is enabled
	 * and we actually have a results flist.
	 */
	if(rlistp != (pin_flist_t *)NULL) {
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"fm_cust_pol_is_brandname_unique_within_brand search output flist:",
			rlistp);
	}

	/* 
	 * See if there is a brand out there right now that already has
	 * this name. If so, flag it as an error.
	 */
	cookie = (pin_cookie_t)NULL;
	int_val = 0;
	PIN_FLIST_ELEM_GET_NEXT(rlistp, PIN_FLD_RESULTS, &int_val, 1, 
		&cookie, ebufp);
	if(int_val > 0) {
		*r_flistpp = PIN_FLIST_CREATE(ebufp);
		PIN_FLIST_FLD_SET(*r_flistpp, PIN_FLD_POID, (void *)poidp, 
			ebufp);
		fm_cust_pol_valid_add_fail(*r_flistpp, 
			PIN_FLD_NAME,
			0,
			PIN_CUST_VAL_ERR_DUPE,
			PIN_CUST_DUPE_VALUE_ERR_MSG,
			(void *)namep, ebufp);

		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_DUPLICATE, PIN_FLD_NAME, 
			0, 0);
	}

cleanup:
	/*
	 * Cleanup and return
	 */
	PIN_FLIST_DESTROY_EX(&flistp, NULL);
	PIN_FLIST_DESTROY_EX(&rlistp, NULL);
	PIN_POID_DESTROY(g_pdp, NULL);
}
/**********************************************************************
 * fm_pymt_pol_spec_collect_get_ach()
 * Get ACH information
 **********************************************************************/
static void
fm_pymt_pol_spec_collect_get_ach(
	pcm_context_t	*ctxp,
	int32		flags,
	pin_flist_t	*i_flistp,
	pin_flist_t	*o_flistp,
	pin_errbuf_t	*ebufp)
{

	void		*vp		= NULL;
	pin_flist_t	*flistp		= NULL;
	pin_flist_t	*p_flistp	= NULL;
	pin_flist_t	*rp_flistp	= NULL;
	pin_flist_t	*a_flistp	= NULL;
	pin_flist_t	*ra_flistp	= NULL;
	int32		rec_id		= 0;
	poid_t		*p_pdp		= NULL;
	poid_t		*a_pdp		= NULL;

	if (PIN_ERR_IS_ERR(ebufp)) {
		return;
	}

	PIN_ERR_CLEAR_ERR(ebufp);

	p_pdp = PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_PAYINFO_OBJ, 0, ebufp);
        a_pdp = PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_POID, 0, ebufp);
	
	/** read the payinfo to get the ach pointer. **/
	p_flistp = PIN_FLIST_CREATE(ebufp);
	PIN_FLIST_FLD_SET(p_flistp, PIN_FLD_POID, p_pdp, ebufp);
	PIN_FLIST_FLD_SET(p_flistp, PIN_FLD_ACH, &rec_id, ebufp);
	
	PCM_OP(ctxp, PCM_OP_READ_FLDS, PCM_OPFLG_READ_UNCOMMITTED, 
					p_flistp, &rp_flistp, ebufp);	

	if (rp_flistp != (pin_flist_t *)NULL) {
		vp = PIN_FLIST_FLD_GET(rp_flistp, PIN_FLD_ACH, 0, ebufp);
		
		if (vp) {
			rec_id = *(int32 *)vp;
		}
                a_flistp = PIN_FLIST_CREATE(ebufp);
                PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_POID, a_pdp, ebufp);
                PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_ACH,
                                                (void *) &rec_id, ebufp);

                PCM_OP(ctxp, PCM_OP_PYMT_GET_ACH_INFO, 0, a_flistp,
                                                &ra_flistp, ebufp);

                flistp = PIN_FLIST_ELEM_GET(ra_flistp, PIN_FLD_RESULTS, 0,
                                                PIN_ELEMID_ANY, ebufp);

                vp = PIN_FLIST_FLD_GET(flistp, PIN_FLD_MERCHANT, 0, ebufp);
                PIN_FLIST_FLD_SET(o_flistp, PIN_FLD_MERCHANT, vp, ebufp);

                PIN_FLIST_FLD_SET(o_flistp, PIN_FLD_ACH, (void *) &rec_id, ebufp);

                vp = PIN_FLIST_FLD_TAKE(flistp, PIN_FLD_POID_VAL, 0, ebufp);

                flistp = PIN_FLIST_ELEM_ADD(o_flistp, PIN_FLD_BATCH_INFO, 0,
                                                                ebufp);
                PIN_FLIST_FLD_PUT(flistp, PIN_FLD_POID_VAL, vp, ebufp);
	}

	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
				"fm_pymt_pol_spec_collect_get_ach error", ebufp);
	}

	PIN_FLIST_DESTROY_EX(&p_flistp, NULL);
	PIN_FLIST_DESTROY_EX(&rp_flistp, NULL);
	PIN_FLIST_DESTROY_EX(&a_flistp, NULL);
	PIN_FLIST_DESTROY_EX(&ra_flistp, NULL);

	return;
}
//****************************************************
// updateStatus
// Pre:
// Post:
//
bool bs_UpdateStatus::updateStatus(
  pin_Session * pinp,
  poid_t * account_pdp,
  poid_t * service_pdp,
  int status,
  int status_flags,
  string source,
  string description,
  pin_flist_t   **return_flistpp,
  pin_errbuf_t  *ebufp  )
{
  pin_flist_t * x_flistp = NULL;
  pin_flist_t * d_flistp = NULL;
  pin_flist_t * f_flistp = NULL;
  pin_flist_t * f_outflistp = NULL;
  pin_errbuf_t  localebuf;
  int     flag=status_flags;
  poid_t * pdp = NULL;
  void * vp = NULL;
  bool rc;

  const string this_program("updateStatus");
  if ( source.empty() )
  {
    source.assign(this_program);
  }
  if ( description.empty() )
  {
    description.assign(this_program);
  }

  PIN_ERR_CLEAR_ERR(ebufp);

  //--enter function--------------
  PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)this_program.c_str() );


  /*--- Create set_status ---*/
  if ( status == PIN_STATUS_ACTIVE && status_flags <= 0 )
  {
    PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_ERROR,
      (char*)"This is an activation - get existing flags" );

    PIN_ERR_CLEAR_ERR(&localebuf);
    pdp = ( pin_poid_is_null(service_pdp)) ? account_pdp : service_pdp;

    f_flistp = PIN_FLIST_CREATE(ebufp);
    PIN_FLIST_FLD_SET(f_flistp, PIN_FLD_POID, (void*)pdp, &localebuf);
    PIN_FLIST_FLD_SET(f_flistp, PIN_FLD_STATUS_FLAGS, (void*)NULL, &localebuf);
    if ( pinp->call_opcode( PCM_OP_READ_FLDS, 0, f_flistp, &f_outflistp, &localebuf))
    {
      if ((vp=PIN_FLIST_FLD_GET(
        f_outflistp, PIN_FLD_STATUS_FLAGS, 1, &localebuf )) != NULL )
        status_flags = *(int*)vp;
    }
    if (f_flistp) PIN_FLIST_DESTROY(f_flistp,NULL); f_flistp = NULL;
    if (f_outflistp) PIN_FLIST_DESTROY_EX(&f_outflistp,NULL); f_outflistp = NULL;
  }
  if ( status_flags < 0) {
    status_flags = 0;
  }

  /*--- Create set_status ---*/
  x_flistp = PIN_FLIST_CREATE(ebufp);
  PIN_FLIST_FLD_SET(x_flistp, PIN_FLD_POID, account_pdp, ebufp);
  if ( ! pin_poid_is_null(service_pdp) )
    PIN_FLIST_FLD_SET(x_flistp, PIN_FLD_SERVICE_OBJ, service_pdp, ebufp);
  PIN_FLIST_FLD_SET(x_flistp, PIN_FLD_PROGRAM_NAME, (void*)source.c_str(), ebufp);
  PIN_FLIST_FLD_SET(x_flistp, PIN_FLD_DESCR, (void*)description.c_str(), ebufp);
  d_flistp = PIN_FLIST_ELEM_ADD( x_flistp, PIN_FLD_STATUSES, PIN_ELEMID_ASSIGN, ebufp );
    PIN_FLIST_FLD_SET(d_flistp, PIN_FLD_STATUS, (void*)&status, ebufp);
    PIN_FLIST_FLD_SET(d_flistp, PIN_FLD_STATUS_FLAGS, (void*)&status_flags, ebufp);

  if ( (! pin_poid_is_null(service_pdp)) && (status == PIN_STATUS_CLOSED) ) {
     rc = pinp->call_opcode(
         PCM_OP_CUST_SET_STATUS, 0, x_flistp, return_flistpp, ebufp);
  }
  else {
     rc = pinp->call_opcode(
         UOL_OP_SET_STATUS, 0, x_flistp, return_flistpp, ebufp);
  }

  PIN_ERR_LOG_FLIST(
    PIN_ERR_LEVEL_DEBUG,(char*)"leaving bs_UpdateStatus::updateStatus" , *return_flistpp );

  if (x_flistp) PIN_FLIST_DESTROY(x_flistp,NULL);
  return rc;
}
/************************************************************************
 * fm_cust_pol_valid_add_fail():
 *
 *   	Add a field validation failure element to the given flist
 *	using the info passed in. We assume the flist has N field
 *	failures on it already with element ids of 0 to (N-1) so
 *	we add a new element with an element id of N.
 *
 *	No error checking is done on the values passed in, but we
 *	do allow for some values to be optional according to the
 *	PCM_OP_CUST_POL_VALID_* return flist specs.
 *
 *	We return a pointer to the element we add to facilitate
 *	layering (by the caller) of the validation failures within
 *	substruct and array fields.
 *
 ************************************************************************/
pin_flist_t *
fm_cust_pol_valid_add_fail(
	pin_flist_t	*r_flistp,
	u_int		field,
	u_int		elemid,
	u_int		result,
	char		*descr,
	void		*val,
	pin_errbuf_t	*ebufp)
{
	pin_flist_t	*flistp = NULL;
	u_int		my_id = 0;
	u_int		type = 0;
	u_int		fail = 0;

	if (PIN_ERR_IS_ERR(ebufp))
		return(flistp);
	PIN_ERR_CLEAR_ERR(ebufp);
	
	/****************************************************************
	 * Create the field failure element.
	 ****************************************************************/
	my_id = PIN_FLIST_ELEM_COUNT(r_flistp, PIN_FLD_FIELD, ebufp); 
	flistp = PIN_FLIST_ELEM_ADD(r_flistp, PIN_FLD_FIELD, my_id, ebufp);

	/****************************************************************
	 * If this is the first time, mark the main result as _FAILED.
	 ****************************************************************/
	if (my_id == 0) {
		fail = PIN_CUST_VERIFY_FAILED;
		PIN_FLIST_FLD_SET(r_flistp, PIN_FLD_RESULT,
			(void *)&fail, ebufp);
	}

	/****************************************************************
	 * The required fields.
	 ****************************************************************/
	/*
	** PIN_FLD_FIELD_NUM.
	*/
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_FIELD_NUM, (void *)&field, ebufp);

	/*
	** PIN_FLD_RESULT.
	*/
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, (void *)&result, ebufp);

	/****************************************************************
	 * The optional fields.
	 ****************************************************************/
	/*
	** PIN_FLD_ELEMENT_ID
	*/
	if (elemid != (u_int)NULL) {
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_ELEMENT_ID,
			(void *)&elemid, ebufp);
	}

	/*
	** PIN_FLD_DESCR.
	*/
	if (descr != (char *)NULL) {
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void *)descr, ebufp);
	}

	/*
	** The actual field value.
	*/
	type = PIN_FIELD_GET_TYPE(field);
	switch (type) {
	case PIN_FLDT_ARRAY:
	case PIN_FLDT_SUBSTRUCT:
		break;
	default:
		/* Val reqd on list - even if NULL */
		PIN_FLIST_FLD_SET(flistp, field, (void *)val, ebufp);
	}

	/* Error? */
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"error", ebufp);
	}

	return(flistp);
}
//****************************************************
// createRecourse
// Pre:
// Post:
//
void bs_CreateLECRecourse::createRecourse(
	pin_Session * pinp,
	const char * sRecordType,
	const char * sBtn,
	const char * sAuthDate,
	const char * sReasonCode,
	const char * sAmount,
	const char * sVersion,
	const char * file_name,
	pin_flist_t   **return_flistpp,
	pin_errbuf_t  *ebufp  )
{
	pin_flist_t * x_flistp = NULL;
	pin_flist_t * c_flistp = NULL;
	int    lec_db = 5;  //WIP:  hard coded
	int    command = 9;
	poid_t * pdp = NULL;
	pin_decimal_t * amtp = NULL;
	void * vp = NULL;
	int impact_type = 0;
	int version = 0; 

	PIN_ERR_CLEAR_ERR(ebufp);

	//--enter function--------------
	PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "bs_CreateLECRecourse::createRecourse: enter" );

	/*--- Convert ---*/
	if (sVersion && strlen(sVersion)> 0 )
		version = atoi(sVersion);

	amtp = pbo_decimal_from_str(sAmount,ebufp);
	if(amtp && !PIN_ERR_IS_ERR(ebufp) 
		&& pbo_decimal_sign(amtp, ebufp) == -1 )
	{
		pbo_decimal_abs_assign(amtp, ebufp);
		impact_type = 1;
	}


	/*--- Create set_status ---*/
	x_flistp = PIN_FLIST_CREATE(ebufp);
	pdp = pin_poid_create((int64)lec_db,"/_lec_db", (int64)1, ebufp);
	PIN_FLIST_FLD_PUT(x_flistp, PIN_FLD_POID, pdp, ebufp);
	PIN_FLIST_FLD_SET(x_flistp, PIN_FLD_COMMAND, (void*)&command, ebufp);
	c_flistp = PIN_FLIST_ELEM_ADD( x_flistp, PIN_FLD_CHARGES, PIN_ELEMID_ASSIGN, ebufp );
		PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_PHONE, (void*)sBtn, ebufp);
		PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_AUTH_DATE, (void*)sAuthDate, ebufp);
		PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_RECORD_TYPE, (void*)sRecordType, ebufp);
		PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_REASON_CODE, (void*)sReasonCode, ebufp);
		PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_IMPACT_TYPE, (void*)&impact_type, ebufp);
		PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_VERSION_ID, (void*)&version, ebufp);
		PIN_FLIST_FLD_PUT(c_flistp, PIN_FLD_AMOUNT_ADJUSTED, (void*)amtp, ebufp);
	
	if (file_name != NULL ) {
		c_flistp = PIN_FLIST_ELEM_ADD( x_flistp, PIN_FLD_BATCH_INFO, PIN_ELEMID_ASSIGN, ebufp );
			PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_FILENAME, (void*)file_name, ebufp);
	}


	/*----* Connect to the LEC DM *---*/
//	pcm_context_t	*my_ctxp = NULL;
//	PCM_CONTEXT_OPEN(&my_ctxp, (pin_flist_t *)0, ebufp);

	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,"dm search input flist", x_flistp);
	pinp->call_opcode(
         PCM_OP_SEARCH, 0, x_flistp, return_flistpp, ebufp);
	if (return_flistpp) PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "dm search output flist", *return_flistpp);

//	if ( PIN_ERR_IS_ERR(ebufp) )
//	{
//		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,"Failed connecting to DM_LEC...", ebufp );
//	}
//	PCM_CONTEXT_CLOSE(my_ctxp, 0, NULL);

	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,(char*)"leaving bs_CreateLECRecourse::createRecourse" , *return_flistpp );

	PIN_FLIST_DESTROY_EX(&x_flistp,NULL);
	return;
}
Пример #10
0
/*******************************************************************
 * fm_pymt_pol_charge_set_reason_id()
 * This function sets the PIN_FLD_REASON_ID
 *******************************************************************/
static void
fm_pymt_pol_charge_set_reason_id(
	pcm_context_t           *ctxp,
	pin_flist_t		*i_flistp,
	pin_errbuf_t		*ebufp)
{
	pin_flist_t		*res_flistp = NULL;
	pin_flist_t		*reason_flistp = NULL;
	pin_flist_t		*p_flistp = NULL;
	pin_flist_t		*iinfo_flistp = NULL;
	pin_cookie_t            cookie = NULL;
	int32			domain_id = PIN_PYMT_REASON_DOMAIN_ID;
	int32			reason_id = 0;
	int32			elem_id  = 0;
	void 			*vp = NULL;
	
	if (PIN_ERR_IS_ERR(ebufp))
	{
		return ;
	}
	PIN_ERR_CLEAR_ERR(ebufp);

	vp = (int32 *) PIN_FLIST_FLD_GET(i_flistp,
			PIN_FLD_STR_VERSION, 1, ebufp);
	if(vp){
		domain_id = * (int32 *) vp;
	}

	while ((res_flistp = PIN_FLIST_ELEM_GET_NEXT(i_flistp, PIN_FLD_RESULTS,
                        &elem_id, 1, &cookie, ebufp)) != NULL) {
                p_flistp = PIN_FLIST_SUBSTR_GET(res_flistp,
                                        PIN_FLD_PAYMENT, 1, ebufp);
		if(p_flistp)
		{
			iinfo_flistp = PIN_FLIST_SUBSTR_GET(p_flistp, 
					PIN_FLD_INHERITED_INFO, 1, ebufp);
			if (iinfo_flistp) {
				fm_pymt_pol_charge_process_result(ctxp, 
						iinfo_flistp,
						&reason_id,
						&domain_id,
						ebufp);
				reason_flistp = PIN_FLIST_ELEM_ADD(res_flistp,
							PIN_FLD_PAYMENT_REASONS,
							0, ebufp);
				PIN_FLIST_FLD_SET(reason_flistp,
						PIN_FLD_REASON_ID,
						(void *) &reason_id, ebufp);
				fm_pymt_pol_charge_set_domain_id(ctxp,
						p_flistp,
						reason_flistp,
						&domain_id,
						ebufp);
				
			}
		}
	}
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_DEBUG,
				"fm_pymt_pol_charge_set_reason_id", ebufp);
	}

	return;
}
Пример #11
0
/*******************************************************************
 * Step search.
 *
 *	Performs a read-object step search for services with
 *	md5 encrypted passwords. The first 10 such services are
 *	retrieved in two blocks of 5 services each.
 *
 *	The "one arg like" search for /service is 236.
 *
 *******************************************************************/
void
sample_step_search(
	pcm_context_t	*ctxp,
	u_int64		database,
	pin_errbuf_t	*ebufp)
{
	pin_flist_t	*flistp = NULL;
	pin_flist_t	*a_flistp = NULL;
	pin_flist_t	*r_flistp = NULL;

	poid_t		*objp = NULL;
	u_int64		id;
	char		*passwd = "md5|%";
	pin_cookie_t	cookie = NULL;
	int32		rec_id;


	/***********************************************************
	 * Check the error buffer.
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Allocate the flist for searching.
	 ***********************************************************/
	flistp = PIN_FLIST_CREATE(ebufp);

	/***********************************************************
	 * Allocate the search poid and give it to the flist.
	 ***********************************************************/
	id = (u_int64)236;

	objp = PIN_POID_CREATE(database, "/search", id, ebufp);
	PIN_FLIST_FLD_PUT(flistp, PIN_FLD_POID, (void *)objp, ebufp);

	/***********************************************************
	 * Add a search arguments array.
	 ***********************************************************/
	a_flistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 1, ebufp);

	/***********************************************************
	 * Put the password value in element 1 of the args array.
	 ***********************************************************/
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_PASSWD, (void *)passwd, ebufp);

	/***********************************************************
	 * Add a search results marker.
	 *
	 * Making this NULL forces the read-object result we want.
	 * The key here is the value 5, which says give me the
	 * first 5 results or objects.
	 ***********************************************************/
	a_flistp = (pin_flist_t *)NULL;
	PIN_FLIST_ELEM_PUT(flistp, a_flistp, PIN_FLD_RESULTS, 5, ebufp);

	/***********************************************************
	 * Call the DM to initiate the step search.
	 ***********************************************************/
	PCM_OP(ctxp, PCM_OP_STEP_SEARCH, 0, flistp, &r_flistp, ebufp);

        /***********************************************************
         * Walk the first results array.
         ***********************************************************/
	fprintf(stdout,"\n** The first 5 objects:\n");
        a_flistp = PIN_FLIST_ELEM_GET_NEXT(r_flistp, PIN_FLD_RESULTS,
                &rec_id, 1, &cookie, ebufp);
        while (a_flistp != (pin_flist_t *)NULL) {

                /***************************************************
                 * Show this result.
                 ***************************************************/
                fprintf(stdout,"\nStep Search Result(%d) Flist:\n", rec_id);
                PIN_FLIST_PRINT(a_flistp, stdout, ebufp);

                /***************************************************
                 * Get the next result.
                 ***************************************************/
                a_flistp = PIN_FLIST_ELEM_GET_NEXT(r_flistp,
                        PIN_FLD_RESULTS, &rec_id, 1, &cookie, ebufp);
        }

	/***********************************************************
	 * Recycle the results flist.
	 ***********************************************************/
	PIN_FLIST_DESTROY(r_flistp, NULL);
	r_flistp = (pin_flist_t *)NULL;

	/***********************************************************
	 * Call the DM to get the next 5 objects using step next.
	 ***********************************************************/
	PCM_OP(ctxp, PCM_OP_STEP_NEXT, 0, flistp, &r_flistp, ebufp);

        /***********************************************************
         * Walk the next results array.
         ***********************************************************/
	fprintf(stdout,"\n** The next 5 objects:\n");
	cookie = NULL;
        a_flistp = PIN_FLIST_ELEM_GET_NEXT(r_flistp, PIN_FLD_RESULTS,
                &rec_id, 1, &cookie, ebufp);
        while (a_flistp != (pin_flist_t *)NULL) {

                /***************************************************
                 * Show this result.
                 ***************************************************/
                fprintf(stdout,"\nStep Search Result(%d) Flist:\n", rec_id);
                PIN_FLIST_PRINT(a_flistp, stdout, ebufp);

                /***************************************************
                 * Get the next result.
                 ***************************************************/
                a_flistp = PIN_FLIST_ELEM_GET_NEXT(r_flistp,
                        PIN_FLD_RESULTS, &rec_id, 1, &cookie, ebufp);
        }

	/***********************************************************
	 * Recycle the results flist.
	 ***********************************************************/
	PIN_FLIST_DESTROY(r_flistp, NULL);
	r_flistp = (pin_flist_t *)NULL;

	/***********************************************************
	 * Call the DM to end step searching.
	 ***********************************************************/
	PCM_OP(ctxp, PCM_OP_STEP_END, 0, flistp, &r_flistp, ebufp);

	/***********************************************************
	 * Clean up.
	 ***********************************************************/
	/* Free local memory */
	PIN_FLIST_DESTROY(r_flistp, NULL);
	PIN_FLIST_DESTROY(flistp, NULL);

	/* Error? */
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"sample_step_search error", ebufp);
	}

	return;
}
/*******************************************************************
 * fm_cust_pol_get_plans_search():
 *******************************************************************/
static void
fm_cust_pol_get_plans_search(
	pcm_context_t	*ctxp,
	int64		database,
	char		*name,
	char		*type,
	pin_flist_t	**o_flistpp,
	pin_errbuf_t	*ebufp)
{
	pin_cookie_t	cookie = NULL;
	pin_flist_t	*s_flistp = NULL;
	pin_flist_t	*r_flistp = NULL;
	pin_flist_t	*flistp = NULL;
	poid_t		*pdp = NULL;
	poid_t		*brand_poidp = NULL;
	int32		cred = 0;

	int32		element_id;
	u_int		uint_val;

	/*
	 * Safety check.
	 */
	if ((name == (char *)NULL) || (type == (char *)NULL)) {
		return;
	}

	/*
	 * Create the search flist
	 *
	 * In a branding configuration, it is possible that the 
	 * account A belonging to a brand B might reside in a non-primary
	 * database. This implies that DM does not have information about
	 * the brand B owner to do the appropriate scoping. Therefore, we
	 * should disable the scoping temporarily for this search.
	 *
	 * Since we disable scoping, we need explicitly filter out the 
	 * plan lists that do not belong to this brand using the brand owner
	 * in the query.
	 *
	 */
	s_flistp = PIN_FLIST_CREATE(ebufp);

	pdp = PIN_POID_CREATE(database, "/search", (int64)-1, ebufp);
	PIN_FLIST_FLD_PUT(s_flistp, PIN_FLD_POID, (void *)pdp, ebufp);
	uint_val = SRCH_DISTINCT;
	PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_FLAGS, (void *)&uint_val, ebufp);
	PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_TEMPLATE, 
		(void *)  "select X from /group/$1 where " 
			  "F1 = V1 and F2 = V2 and F3 = V3 and F4 = V4", ebufp);

	PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_PARAMETERS, (void *)"plan_list", 
		ebufp); 

	flistp = PIN_FLIST_ELEM_ADD(s_flistp, PIN_FLD_ARGS, 1, ebufp); 
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_NAME, (void *)name, ebufp); 

	flistp = PIN_FLIST_ELEM_ADD(s_flistp, PIN_FLD_ARGS, 2, ebufp); 
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE_STR, (void *)type, ebufp); 

	flistp = PIN_FLIST_ELEM_ADD(s_flistp, PIN_FLD_ARGS, 3, ebufp); 
	pdp = PIN_POID_CREATE(database, "/group/plan_list", (int64)-1, ebufp); 

	PIN_FLIST_FLD_PUT(flistp, PIN_FLD_POID, (void *)pdp, ebufp); 
	flistp = PIN_FLIST_ELEM_ADD(s_flistp, PIN_FLD_ARGS, 4, ebufp);

	brand_poidp = cm_fm_perm_get_brand_account(ebufp);
        if(PIN_POID_IS_NULL(brand_poidp)) {
		brand_poidp = fm_utils_lineage_root_poid(database, ebufp);
        } else {
		if (PIN_POID_GET_ID(brand_poidp) == 1) {
			brand_poidp = PIN_POID_CREATE(database,
					PIN_POID_GET_TYPE(brand_poidp), 
					PIN_POID_GET_ID(brand_poidp), ebufp);
		} else {
			brand_poidp = PIN_POID_COPY(brand_poidp, ebufp);
		}
        }

        PIN_FLIST_FLD_PUT(flistp, PIN_FLD_ACCOUNT_OBJ, (void *)brand_poidp, 
			ebufp);


	flistp = PIN_FLIST_ELEM_ADD(s_flistp, PIN_FLD_RESULTS, 0, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_POID, (void *)NULL, ebufp);
	PIN_FLIST_ELEM_SET(flistp, (pin_flist_t *)NULL, PIN_FLD_MEMBERS,
		PIN_ELEMID_ANY, ebufp);
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
                "op_cust_pol_get_plans search flist", s_flistp);

	/*
	 * Do the search
	 */
        cred = CM_FM_BEGIN_OVERRIDE_SCOPE(CM_CRED_SCOPE_OVERRIDE_ROOT);
	PCM_OP(ctxp, PCM_OP_SEARCH, 0, s_flistp, &r_flistp, ebufp);
        CM_FM_END_OVERRIDE_SCOPE(cred);

	/*
	 * We want what is in the result element (assume only one)
	 */
	cookie = NULL;
	*o_flistpp = PIN_FLIST_ELEM_TAKE_NEXT(r_flistp, PIN_FLD_RESULTS,
		&element_id, 1, &cookie, ebufp);

	/*
	 * Clean up.
	 */
	PIN_FLIST_DESTROY_EX(&s_flistp, NULL);
	PIN_FLIST_DESTROY_EX(&r_flistp, NULL);

	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_cust_pol_get_plans_search error", ebufp);
	}

	return;
}
Пример #13
0
/*******************************************************************
 * fm_pymt_pol_collect_result_soft():
 *
 *	Create the collect result for 'soft' pin declines.
 *
 *	All soft declines are subject to the same rules, but
 *	we may need/want to treat each command differently.
 *
 *******************************************************************/
static void
fm_pymt_pol_collect_result_soft(
	pcm_context_t		*ctxp,
	pin_flist_t		*i_flistp,
	pin_flist_t		*r_flistp,
	pin_errbuf_t		*ebufp)
{
	pin_flist_t		*a_flistp = NULL;
	pin_flist_t		*b_flistp = NULL;
	pin_flist_t		*flistp = NULL;
	pin_cookie_t		cookie = NULL;

	int			result;
	int			rec_id;
	char			*descr = NULL;
	pin_status_t		*status = NULL;
	int			*flags = NULL;
	poid_t			*a_pdp = NULL;
	poid_t			*s_pdp = NULL;
	poid_t			*b_pdp = NULL;
	void			*vp = NULL;
	char			*templatep;
	int32			srch_flags = SRCH_DISTINCT;

	int			item_status = PIN_ITEM_STATUS_OPEN;
	pin_decimal_t		*item_due = NULL;
	time_t			start_t = 0;

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	item_due = pbo_decimal_from_str("0.01", ebufp);

	/***********************************************************
	 * All get the FAIL result and default descr.
	 ***********************************************************/
	result = PIN_RESULT_FAIL;
	PIN_FLIST_FLD_SET(r_flistp, PIN_FLD_RESULT, (void *)&result, ebufp);
	descr = "creditcard operation declined";
	PIN_FLIST_FLD_SET(r_flistp, PIN_FLD_DESCR, (void *)descr, ebufp);

	/***********************************************************
	 * Read the config info.
	 ***********************************************************/
	fm_pymt_pol_collect_config(ctxp, i_flistp, &b_flistp, ebufp);

	/***********************************************************
	 * If not already inactive for debt/closed, suspend.
	 ***********************************************************/
	status = (pin_status_t *)PIN_FLIST_FLD_GET(b_flistp,
		PIN_FLD_STATUS, 0, ebufp);
	flags = (int *)PIN_FLIST_FLD_GET(b_flistp,
		PIN_FLD_STATUS_FLAGS, 0, ebufp);
	a_pdp = (poid_t *)PIN_FLIST_FLD_GET(b_flistp, 
		PIN_FLD_POID, 0, ebufp);
	b_pdp = (poid_t *)PIN_FLIST_FLD_GET(b_flistp, 
		PIN_FLD_LAST_BILL_OBJ, 0, ebufp);

	/***********************************************************
	 * Nothing to do, if there was no last bill object.
	 ***********************************************************/
	if (PIN_POID_IS_NULL(b_pdp)) {
		PIN_FLIST_DESTROY_EX(&b_flistp, NULL);
		pbo_decimal_destroy(&item_due);
		return;
	}

	/***********************************************************
	 * Read the bill object for the start of the billing cycle.
	 ***********************************************************/
	vp = (void *)NULL;
	a_flistp = PIN_FLIST_CREATE(ebufp);
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_POID, (void *)b_pdp, ebufp);
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_START_T, vp, ebufp);

	/***********************************************************
	 * Read the info from the last bill object.
	 ***********************************************************/
	PCM_OP(ctxp, PCM_OP_READ_FLDS, 0, a_flistp, &flistp, ebufp);
	vp = PIN_FLIST_FLD_GET(flistp, PIN_FLD_START_T, 0,ebufp);
	if (vp) start_t = *((time_t *)vp);

	PIN_FLIST_DESTROY_EX(&a_flistp, NULL);
	PIN_FLIST_DESTROY_EX(&flistp, NULL);
	
	/***********************************************************
	 * Allocate the flist for search the item objects.
	 ***********************************************************/
	a_flistp = PIN_FLIST_CREATE(ebufp);

	/**************************************************************
	 * Construct the search poid.
	 **************************************************************/
	s_pdp = PIN_POID_CREATE(PIN_POID_GET_DB(a_pdp), "/search/pin", 
		-1, ebufp);
	PIN_FLIST_FLD_PUT(a_flistp, PIN_FLD_POID, (void *)s_pdp, ebufp);
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_FLAGS, &srch_flags, ebufp);

	/**************************************************************
	 * Specify the search arguments.
	 **************************************************************/
	flistp = PIN_FLIST_ELEM_ADD(a_flistp, PIN_FLD_ARGS, 1, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_ACCOUNT_OBJ, (void *)a_pdp, ebufp);

	flistp = PIN_FLIST_ELEM_ADD(a_flistp, PIN_FLD_ARGS, 2, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_STATUS, (void *)&item_status, ebufp);

	flistp = PIN_FLIST_ELEM_ADD(a_flistp, PIN_FLD_ARGS, 3, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_DUE, (void *)item_due, ebufp);

	flistp = PIN_FLIST_ELEM_ADD(a_flistp, PIN_FLD_ARGS, 4, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_EFFECTIVE_T, (void *)&start_t, ebufp);

	templatep = "select X from /item/$1 "
		" where F1 = V1 "
		" and F2 = V2 "
		" and F3 >= V3 "
		" and F4 <= V4 ";
 
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_TEMPLATE, (void *)templatep, 
		ebufp);
	/**************************************************************
	 * Set-up the results array.
	 **************************************************************/
	vp = (void *)NULL;
	flistp = PIN_FLIST_ELEM_ADD(a_flistp, PIN_FLD_RESULTS, 0, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_POID, vp, ebufp);

	/**************************************************************
	 * Call the PCM_OP_SEARCH opcode to do the actual search.
	 **************************************************************/
	PCM_OP(ctxp, PCM_OP_SEARCH, 0, a_flistp, &flistp, ebufp);
	PIN_FLIST_DESTROY_EX(&a_flistp, NULL);

	/**************************************************************
	 * Did we find any items with 30 days due.
	 **************************************************************/
	a_flistp = PIN_FLIST_ELEM_GET_NEXT(flistp, PIN_FLD_RESULTS,
                &rec_id, 1, &cookie, ebufp);

	if ((a_flistp != (pin_flist_t *)NULL) && (status)) {
		switch (*status) {
		case PIN_STATUS_INACTIVE:
			if (flags && (*flags & PIN_STATUS_FLAG_DEBT))
				break;
			/* intentional fall-thru */
		case PIN_STATUS_ACTIVE:
			fm_pymt_pol_collect_set_status(r_flistp,
			    PIN_STATUS_INACTIVE, PIN_STATUS_FLAG_DEBT,
			    "credit card pastdue", ebufp);
			break;
		case PIN_STATUS_CLOSED:
			break;
                default:
                       break;  
		}
	}

	/***********************************************************
	 * Someday check for age of debt and close after so long.
	 ***********************************************************/

	/***********************************************************
	 * Cleanup.
	 ***********************************************************/

	PIN_FLIST_DESTROY_EX(&b_flistp, NULL);
	PIN_FLIST_DESTROY_EX(&flistp, NULL);
	pbo_decimal_destroy(&item_due);

	/* Error? - caught/logged by caller */

	return;
}
/******************************************************
 * Stuff a config parameter into outgoing flist, 
 * depending on string value
 ******************************************************/
static void
fm_cust_pol_get_config_stuff(
	pin_flist_t		*r_flistp,
	char			*key,
	char			*val,
	pin_errbuf_t		*ebufp)
{
	pin_errbuf_t		errbuf;
	u_int			type;
	pin_flist_t		*flistp = NULL;
	u_int			port = 0;

	if(ebufp == NULL) ebufp = &errbuf;

	PIN_ERR_CLEAR_ERR(ebufp);

	if(key == NULL) {
		return;
	}

	/*
	 * If DNS Address param, then create host array entry
	 */
	else if( strcmp( key, "dns_address_1")==0) {
		flistp = PIN_FLIST_ELEM_ADD(r_flistp, PIN_FLD_HOST, 1, ebufp);

		PIN_FLIST_FLD_SET(flistp, PIN_FLD_HOSTNAME, (void *)val, ebufp);

		type = PIN_HOST_DNS;
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE, (void *)&type, ebufp);
	}

	else if (strcmp(key, "dns_address_2") == 0) {
		flistp = PIN_FLIST_ELEM_ADD(r_flistp, PIN_FLD_HOST, 2, ebufp);

		PIN_FLIST_FLD_SET(flistp, PIN_FLD_HOSTNAME, (void *)val, ebufp);

		type = PIN_HOST_DNS;
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE, (void *)&type, ebufp);
	}

	/*
	 * If SMTP Hostname, then look to see if already a
	 * host array elem yet or not.  We will count on it
	 * being in elemid 3, although this is not a hard
	 * and fast rule except for only within this policy
	 * call.  It may have already been setup if the smtp_port
	 * parameter was previously found.
	 */

	else if (strcmp(key, "smtp_hostname") == 0) {
		flistp = PIN_FLIST_ELEM_GET(r_flistp,
			PIN_FLD_HOST, 3, 1, ebufp);

		if (flistp == (pin_flist_t *)NULL) {
			flistp = PIN_FLIST_ELEM_ADD( r_flistp, 
				PIN_FLD_HOST, 3, ebufp);

			type = PIN_HOST_SMTP;
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE,
				(void *)&type, ebufp);
		}

		PIN_FLIST_FLD_SET(flistp, PIN_FLD_HOSTNAME, (void *)val, ebufp);
	}

	/*
	 * If SMTP port, then look to see if already a
	 * host array elem yet or not.  We will count on it
	 * being in elemid 3, although this is not a hard
	 * and fast rule except for only within this policy
	 * call.  It may have already been setup if the smtp_host
	 * parameter was previously found.
	 */
	else if (strcmp(key, "smtp_port") == 0) {
		flistp = PIN_FLIST_ELEM_GET(r_flistp,
			PIN_FLD_HOST, 3, 1, ebufp);

		if (flistp == (pin_flist_t *)NULL) {
			flistp = PIN_FLIST_ELEM_ADD(r_flistp, 
				PIN_FLD_HOST, 3, ebufp);

			type = PIN_HOST_SMTP;
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE,
				(void *)&type, ebufp);
		}

		port = atoi(val);
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_PORT, (void *)&port, ebufp);

	}

	/*
	 * NNTP Hostname
	 */
	else if (strcmp(key, "nntp_hostname") == 0) {
		flistp = PIN_FLIST_ELEM_ADD(r_flistp, PIN_FLD_HOST, 4, ebufp);

		PIN_FLIST_FLD_SET(flistp, PIN_FLD_HOSTNAME, (void *)val, ebufp);

		type = PIN_HOST_NNTP;
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE, (void *)&type, ebufp);
	}

	/*
	 * Pop Host
	 */
	else if (strcmp(key, "pop_hostname") == 0) {
		flistp = PIN_FLIST_ELEM_ADD(r_flistp, PIN_FLD_HOST, 5, ebufp);

		PIN_FLIST_FLD_SET(flistp, PIN_FLD_HOSTNAME, (void *)val, ebufp);

		type = PIN_HOST_POP;
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE, (void *)&type, ebufp);	
	}

	/*
	 * Http URL
	 */
	else if (strcmp(key, "http_url") == 0) {
		PIN_FLIST_FLD_SET(r_flistp, PIN_FLD_HTTP_URL,
			(void *)val, ebufp);
	}

	/*
	 * Support number
	 */
	else if (strcmp(key, "support_number") == 0) {
		PIN_FLIST_FLD_SET(r_flistp, PIN_FLD_SUPPORT_PHONE,
			(void *)val, ebufp);
	}


	return;
/*ErrOut:
	return;*/
}
//****************************************************
// update_contactinfo
// Pre:
// Post:
//
bool bs_UpdateContactInfo::updateContactInfo(
  pin_Session * pinp,
  poid_t * account_pdp,
  bs_SignupRec * bsrp,
  string source,
  pin_flist_t   **return_flistpp,
  pin_errbuf_t  *ebufp  )
{
    pin_flist_t * c_outflistp = NULL;
    pin_flist_t * c_flistp = NULL;
    pin_flist_t * t1_flistp = NULL;
    pin_flist_t * t2_flistp = NULL;
    pin_flist_t * outflistp = NULL;
  void *  vp = NULL;
  int32 flags = 0;

  /* source name */
  /* source / desc name */
  const string this_program("bs_UpdateContactInfo::updateContactInfo");
  if ( source.empty() )
  {
    source.assign(this_program);
  }
  PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)this_program.c_str() );


  //--- get appropriate fields ----------
  char * firstname  = bsrp->s_firstName;
  char * lastname   = bsrp->s_lastName;
  char * address    = bsrp->s_caddress;
  char * city   = bsrp->s_ccity;
  char * state    = bsrp->s_cstate;
  char * zip    = bsrp->s_czip;
  char * email_addr = bsrp->s_cemail_addr;
  int32 contact_type  = PIN_NAMEINFO_BILLING;
  const char * country    = "USA";
  const char * program_name = source.c_str();


  PIN_ERR_CLEAR_ERR(ebufp);

  /* create flist */
  c_flistp = PIN_FLIST_CREATE( ebufp );

  /* top level fields */
  PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_POID,(void *)account_pdp, ebufp);
  PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_PROGRAM_NAME,(void *)program_name, ebufp);

  /* nameinfo */
  t1_flistp = PIN_FLIST_ELEM_ADD(c_flistp, PIN_FLD_NAMEINFO, contact_type, ebufp);
  PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_FIRST_NAME,(void *)firstname, ebufp);
  PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_LAST_NAME,(void *)lastname, ebufp);
  PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_ADDRESS,(void *)address, ebufp);
  PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_CITY,(void *)city, ebufp);
  PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_STATE,(void *)state, ebufp);
  PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_ZIP,(void *)zip, ebufp);
  PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_COUNTRY,(void *)country, ebufp);
  PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_EMAIL_ADDR,(void *)email_addr, ebufp);

  PIN_ERR_CLEAR_ERR(ebufp);

  bool rc = pinp->call_opcode(
    PCM_OP_CUST_POL_UOL_SET_NAMEINFO, flags, c_flistp, &c_outflistp, ebufp);

  if (c_flistp) PIN_FLIST_DESTROY(c_flistp,ebufp);
  if (c_outflistp) PIN_FLIST_DESTROY_EX(&c_outflistp,ebufp);
  return rc;
}
void
fm_cust_pol_valid_login_check_uniquiness_service(
	pcm_context_t		*ctxp,
	int64			db_no,
	int			msexchange_service_type,
	pin_flist_t		*i_flistp,
	pin_flist_t		*r_flistp,
	pin_errbuf_t		*ebufp)
{
	pin_flist_t		*a_flistp = NULL;
	pin_flist_t		*l_flistp = NULL;
	pin_flist_t		*n_flistp = NULL;
	pin_flist_t		*s1_flistp = NULL;
	pin_flist_t		*s2_flistp = NULL;
	pin_flist_t		*flistp = NULL;
	poid_t			*objp = NULL;
	poid_t			*s_pdp = NULL;
	void			*vp = NULL;
	const char		*subtype = NULL;
	char			*login = NULL;
	int32			result = PIN_CUST_VERIFY_PASSED;
	int32			elemid = 0;
	int32			count1 = 0;
	int32			count2 = 0;
	int32			search_flag = SRCH_DISTINCT;
	pin_cookie_t		cookie = NULL;
	pin_cookie_t		cookie2 = NULL;
	int			count = 0;
	int32			cred = 0;

        /***********************************************************
         * Return immediately if there's an error in ebufp.
         ***********************************************************/
        if (PIN_ERR_IS_ERR(ebufp))
                return;
        PIN_ERR_CLEAR_ERR(ebufp);

	s_pdp = (poid_t *)PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_POID, 0, ebufp);
	/*********************************************************
	 * Create the search flist
	 ********************************************************/
	s1_flistp = PIN_FLIST_CREATE(ebufp);
	s2_flistp = PIN_FLIST_CREATE(ebufp);
	objp = PIN_POID_CREATE(db_no, "/search", -1, ebufp);
	PIN_FLIST_FLD_SET(s1_flistp, PIN_FLD_POID, (void *)objp, ebufp);
	PIN_FLIST_FLD_PUT(s2_flistp, PIN_FLD_POID, (void *)objp, ebufp);

	/******************************************************************
	 * Set the search template.
	 ******************************************************************/

	/**********************************************************************
	 * If Service type is /service/msexchange/user or 
	 * /service/msexchange/user/firstadmin
	 * search login name in both /service/msexchange/user and 
	 * /service/msexchange/user/firstadmin objects
	 **********************************************************************/
	if( msexchange_service_type != PIN_MSEXCHANGE_SERVICE_NONE ){
		vp = (void*)"select X from /service where "
				"F1 = V1 AND ( F2 = V2 OR  F3 = V3 ) ";
	}
	else {
		vp = (void*)"select X from /service where "
				" F1 = V1 AND F2 = V2 ";
	}

	PIN_FLIST_FLD_SET(s1_flistp, PIN_FLD_TEMPLATE, vp, ebufp);
	PIN_FLIST_FLD_SET(s2_flistp, PIN_FLD_TEMPLATE, vp, ebufp);
	PIN_FLIST_FLD_SET(s1_flistp, PIN_FLD_FLAGS, &search_flag, ebufp);
	PIN_FLIST_FLD_SET(s2_flistp, PIN_FLD_FLAGS, &search_flag, ebufp);

	/* Add the search criteria. */
	login = PIN_FLIST_FLD_GET( i_flistp, PIN_FLD_LOGIN, 1, ebufp );
	
	/* Look for PIN_FLD_LOG = login */
	l_flistp = PIN_FLIST_ELEM_ADD(s1_flistp, PIN_FLD_ARGS, 1, ebufp);
	PIN_FLIST_FLD_SET(l_flistp, PIN_FLD_LOGIN, (void *)login, ebufp);

	/* Look for PIN_FLD_ALIAS_LIST - PIN_FLD_NAME = login */
	n_flistp = PIN_FLIST_ELEM_ADD(s2_flistp, PIN_FLD_ARGS, 1, ebufp);
	n_flistp = PIN_FLIST_ELEM_ADD(n_flistp, PIN_FLD_ALIAS_LIST, 
					PIN_ELEMID_ANY, ebufp);
	PIN_FLIST_FLD_SET(n_flistp, PIN_FLD_NAME, (void *)login, ebufp);

	/**********************************************************************
	 * If service is /service/msexchange/user type, search login name also
	 * in /service/msexchange/user/firstadmin for unique login name and 
	 * vice versa.
	 * Add F3 and V3 Parameters in search template with service type
	 **********************************************************************/
	if( msexchange_service_type == PIN_MSEXCHANGE_SERVICE_USER ||
		msexchange_service_type == PIN_MSEXCHANGE_SERVICE_FIRSTADMIN ){
		a_flistp = PIN_FLIST_ELEM_ADD(s1_flistp, PIN_FLD_ARGS,2, ebufp);
		objp = PIN_POID_CREATE(db_no, 
			PIN_MSEXCHANGE_SERVICE_TYPE_FIRSTADMIN,
	       		(int64)-1, ebufp);
		PIN_FLIST_FLD_PUT(a_flistp, PIN_FLD_POID, (void *)objp, ebufp);
		PIN_FLIST_ELEM_SET(s2_flistp, a_flistp, PIN_FLD_ARGS, 2, ebufp);

		a_flistp = PIN_FLIST_ELEM_ADD(s1_flistp, PIN_FLD_ARGS,3, ebufp);
		objp = PIN_POID_CREATE(db_no, PIN_MSEXCHANGE_SERVICE_TYPE_USER,
	       		(int64)-1, ebufp);
		PIN_FLIST_FLD_PUT(a_flistp, PIN_FLD_POID, (void *)objp, ebufp);
		PIN_FLIST_ELEM_SET(s2_flistp, a_flistp, PIN_FLD_ARGS, 3, ebufp);
	} else {
		subtype = PIN_POID_GET_TYPE( s_pdp );
		a_flistp = PIN_FLIST_ELEM_ADD(s1_flistp, PIN_FLD_ARGS,2, ebufp);
		objp = PIN_POID_CREATE(db_no, subtype, (int64)-1, ebufp);
		PIN_FLIST_FLD_PUT(a_flistp, PIN_FLD_POID, (void *)objp, ebufp);
		PIN_FLIST_ELEM_SET(s2_flistp, a_flistp, PIN_FLD_ARGS, 2, ebufp);
	}

	PIN_FLIST_ELEM_PUT(s1_flistp, NULL, PIN_FLD_RESULTS, 0, ebufp);
	PIN_FLIST_ELEM_PUT(s2_flistp, NULL, PIN_FLD_RESULTS, 0, ebufp);

	/************************************************************
	 * we only search if there was a login
	 * otherwise this was all setup for the alias list searches.
	 ************************************************************/
	if( login ) {
		cred = CM_FM_BEGIN_OVERRIDE_SCOPE(CM_CRED_SCOPE_OVERRIDE_ROOT);
		PCM_OP(ctxp, PCM_OP_SEARCH, PCM_OPFLG_COUNT_ONLY,
			s1_flistp, &a_flistp, ebufp);

		cookie = NULL;
		(void) PIN_FLIST_ELEM_GET_NEXT(a_flistp, PIN_FLD_RESULTS, 
			&count1, 0, &cookie, ebufp);	
		PIN_FLIST_DESTROY_EX( &a_flistp, NULL );

		PCM_OP(ctxp, PCM_OP_SEARCH, PCM_OPFLG_COUNT_ONLY,
			s2_flistp, &a_flistp, ebufp);
		CM_FM_END_OVERRIDE_SCOPE(cred);

		cookie = NULL;
		(void) PIN_FLIST_ELEM_GET_NEXT(a_flistp, PIN_FLD_RESULTS, 
			&count2, 0, &cookie, ebufp);	
		PIN_FLIST_DESTROY_EX( &a_flistp, NULL );

		if (count1 > 0 || count2 > 0 ) {
			(void)fm_cust_pol_valid_add_fail(r_flistp, 
				PIN_FLD_LOGIN, (u_int)NULL,
				PIN_CUST_VAL_ERR_DUPE,
				PIN_CUST_DUPE_VALUE_ERR_MSG, 
				(void *)login, ebufp);
               		result = PIN_CUST_VERIFY_FAILED;
		}
	}

	/***********************************************************
         * Try to validate all of the alias list
         ***********************************************************/
	cookie = NULL;
	for ( 
		flistp = PIN_FLIST_ELEM_GET_NEXT( i_flistp, PIN_FLD_ALIAS_LIST,
						&elemid, 0, &cookie, ebufp );
		ebufp->pin_err == PIN_ERR_NONE;
		flistp = PIN_FLIST_ELEM_GET_NEXT( i_flistp, PIN_FLD_ALIAS_LIST,
						&elemid, 0, &cookie, ebufp )
	) {

		if ( !flistp ) continue;

		login = PIN_FLIST_FLD_GET( flistp, PIN_FLD_NAME, 0, ebufp );
	
		/**************************************************************
		 * the search flist is still set up we just need to replace
		 * the login value with an alias value.
		 **************************************************************/
		PIN_FLIST_FLD_SET(l_flistp, PIN_FLD_LOGIN, (void *)login, ebufp);
		PIN_FLIST_FLD_SET(n_flistp, PIN_FLD_NAME, (void *)login, ebufp);

		cred = CM_FM_BEGIN_OVERRIDE_SCOPE(CM_CRED_SCOPE_OVERRIDE_ROOT);
		PCM_OP(ctxp, PCM_OP_SEARCH, PCM_OPFLG_COUNT_ONLY,
			s1_flistp, &a_flistp, ebufp);

		cookie2 = NULL;
		(void) PIN_FLIST_ELEM_GET_NEXT(a_flistp, PIN_FLD_RESULTS, 
			&count1, 0, &cookie2, ebufp);	

		PIN_FLIST_DESTROY_EX( &a_flistp, NULL );

		PCM_OP(ctxp, PCM_OP_SEARCH, PCM_OPFLG_COUNT_ONLY,
			s2_flistp, &a_flistp, ebufp);
		CM_FM_END_OVERRIDE_SCOPE(cred);

		cookie2 = NULL;
		(void) PIN_FLIST_ELEM_GET_NEXT(a_flistp, PIN_FLD_RESULTS, 
			&count2, 0, &cookie2, ebufp);	

		PIN_FLIST_DESTROY_EX( &a_flistp, NULL );

		if (count1 > 0 || count2 > 0) {
			pin_fld_num_t field = PIN_FLD_ALIAS_LIST;
			/***************************************************
			 * There is a validation error so normalize it to
			 * the input flist
			 ***************************************************/
			result = PIN_CUST_VERIFY_FAILED;
			count = PIN_FLIST_ELEM_COUNT(r_flistp, PIN_FLD_FIELD, 
					ebufp);
			a_flistp = PIN_FLIST_ELEM_ADD(r_flistp, PIN_FLD_FIELD,
					count, ebufp);
			PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_FIELD_NUM,
					(void *)&field, ebufp);
			PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_ELEMENT_ID,
					(void *)&elemid, ebufp);
			PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_RESULT,
					(void *)&result, ebufp);
			(void)fm_cust_pol_valid_add_fail(a_flistp, 
				PIN_FLD_NAME, (u_int)NULL,
				PIN_CUST_VAL_ERR_DUPE,
				PIN_CUST_DUPE_VALUE_ERR_MSG, 
				(void *)login, ebufp);
			a_flistp = NULL;
		}
	}
	if ( ebufp->pin_err == PIN_ERR_NOT_FOUND ) {
		PIN_ERR_CLEAR_ERR( ebufp );
	}


	if ( result == PIN_CUST_VERIFY_FAILED ) {
		PIN_FLIST_FLD_SET(r_flistp, PIN_FLD_RESULT,
				(void *)&result, ebufp);
	}
	PIN_FLIST_DESTROY_EX( &s1_flistp, NULL );
	PIN_FLIST_DESTROY_EX( &s2_flistp, NULL );
	
}
/*******************************************************************
 * Main routine for the PCM_OP_PYMT_POL_PRE_COLLECT  command
 *******************************************************************/
void
op_pymt_pol_pre_collect(
	cm_nap_connection_t	*connp,
	int			opcode,
	int			flags,
	pin_flist_t		*in_flistp,
	pin_flist_t		**ret_flistpp,
	pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;
	pin_cookie_t		cookie = NULL;
	pin_flist_t		*flistp = NULL;
	pin_flist_t		*c_flistp = NULL;
	pin_flist_t		*chkpt_flistp = NULL;
	pin_flist_t		*rc_flistp = NULL;
	pin_charge_cmd_t	*cmdp = NULL;
	pin_decimal_t		*amtp = NULL;
	poid_t			*a_pdp = NULL;
	double			*d_ptr = NULL;
	char			*descr = NULL;
	int32			*selectp = NULL;
	int32			elemid = 0;
	int32			result = 0;
	int32			err = 0;
	int32			flag = 0;
	int32			sflag = 0;
	int32			rec_id = 0;
	pin_decimal_t		*minimum_pay = NULL;
	pin_decimal_t		*minimum_ref = NULL;
	pin_flist_t		*s_flistp = NULL;
	pin_flist_t		*a_flistp = NULL;
	pin_flist_t		*b_flistp = NULL;
	pin_flist_t		*r_flistp = NULL;
	poid_t			*s_pdp	  = NULL;	  
	int32			*mandate_status = 0;
	pin_pymt_result_t	*statusp = NULL;
	int32			*resultp  = NULL;
	char                    vendor_name[256] = {" "};
 	void                    *vp = NULL;
	char			*dd_vendorp = NULL;
	
	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Null out results until we have some.
	 ***********************************************************/
	*ret_flistpp = (pin_flist_t *)NULL;

	/***********************************************************
	 * Insanity check.
	 ***********************************************************/
	if (opcode != PCM_OP_PYMT_POL_PRE_COLLECT) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"bad opcode in op_pymt_pol_pre_collect", ebufp);
		return;
	}

	/***********************************************************
	 * Debug: What did we get?
	 ***********************************************************/
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_pymt_pol_pre_collect input flist", in_flistp);

	/***********************************************************
	 * Get command from very first element of array
	 * note: we cannot rely that it has index [0] or [1] or ...
	 ***********************************************************/
	flistp = PIN_FLIST_ELEM_GET_NEXT(in_flistp, PIN_FLD_CHARGES, 
					&elemid, 0, &cookie, ebufp);

	cmdp = (pin_charge_cmd_t *)PIN_FLIST_FLD_GET(flistp,
					PIN_FLD_COMMAND, 0, ebufp);
	



	/***********************************************************
	 * Select the list of outstanding checkpoint events.
	 * Checkpoints' existance has sense for following commands only: 
	 * authorization, deposit, conditional deposit and refund
	 ***********************************************************/
	if (cmdp && 
		((*cmdp == PIN_CHARGE_CMD_CONDITION) ||
		 (*cmdp == PIN_CHARGE_CMD_REFUND) ||
		 (*cmdp == PIN_CHARGE_CMD_AUTH_ONLY) ||
		 (*cmdp == PIN_CHARGE_CMD_DEPOSIT))) {
		/***********************************************************
		 * New algorithm is to search for checkpoint upfront and
		 * pass a flag that indicates that search is done
		 ***********************************************************/
		pin_flist_t		*b_flistp = NULL;
		int32			*b_flags = 0;

		/***********************************************************
		 * Get checkpoints' flag from very first element of array
		 * note: we cannot rely that it has index [0] or [1] or ...
		 ***********************************************************/
		elemid = 0;
		cookie = NULL;
		b_flistp = PIN_FLIST_ELEM_GET_NEXT(in_flistp,PIN_FLD_BATCH_INFO,
						   &elemid, 1, &cookie, ebufp);

		if (b_flistp != 0) {
			b_flags = (int32*)PIN_FLIST_FLD_GET(b_flistp,
						PIN_FLD_STATUS_FLAGS, 1, ebufp);
		}

		/***********************************************************
		 * 1. If no flags do checkpoints selection
		 * 2. If flag is not set do checkpoint selection
		 * 3. If flag is set don't perform checkpoint selection
		 ***********************************************************/
		if(!((b_flags != 0)&&(*b_flags & PIN_PAYMENT_BATCH_CHKPTS))){
			fm_pymt_pol_find_outstanding_chkpts(ctxp, in_flistp, 
							&chkpt_flistp, ebufp);
		}
	}

	/***********************************************************
	 * Get the minimum charge amount from the pin.conf. If the
	 * entry is missing from the pin.conf assume the default
	 * minimum value of 2.00
	 ***********************************************************/
	pin_conf("fm_pymt_pol", "minimum_payment", PIN_FLDT_NUM, 
		(caddr_t *)&d_ptr, &err);
	if (d_ptr) {
		minimum_pay = pbo_decimal_from_double(*d_ptr, ebufp);
		free(d_ptr);
        } else {
		minimum_pay = pbo_decimal_from_str("2.00", ebufp);
        }

	/***********************************************************
	 * Get the minimum refund amount from the pin.conf. If the
	 * entry is missing from the pin.conf assume the default
	 * minimum value of -2.00
	 ***********************************************************/
	pin_conf("fm_pymt_pol", "minimum_refund", PIN_FLDT_NUM, 
			(caddr_t *)&d_ptr, &err);
	if (d_ptr) {
		minimum_ref = pbo_decimal_from_double(*d_ptr, ebufp);
		free(d_ptr);
        } else {
		minimum_ref = pbo_decimal_from_str("2.00", ebufp);
	}

	/***********************************************************
	 * Get the dd_vendor value from the pin.conf. 
	 ***********************************************************/
	pin_conf("cm", "dd_vendor", PIN_FLDT_STR, 
			(caddr_t *)&dd_vendorp, &err);

	c_flistp = PIN_FLIST_COPY(in_flistp, ebufp);

	/***********************************************************
	 * Walk the charges array and check each element.
	 ***********************************************************/
	elemid = 0;
	cookie = NULL;

	while ((flistp = PIN_FLIST_ELEM_GET_NEXT(c_flistp, PIN_FLD_CHARGES,
		&elemid, 1, &cookie, ebufp)) != (pin_flist_t *)NULL) {

		statusp = (pin_pymt_result_t *) PIN_FLIST_FLD_GET(flistp,
				PIN_FLD_STATUS, 1, ebufp);
		resultp = (int32 *) PIN_FLIST_FLD_GET(flistp,PIN_FLD_RESULT, 1, ebufp);
                if((statusp && *statusp >= PIN_PYMT_SUSPENSE 
				&& *statusp < PIN_PYMT_FAILED) 
			|| (resultp && *resultp == PIN_PAYMENT_RES_FAIL)){
			/*******************************************
			 * Do nothing if a payment in suspense
			 *******************************************/
			continue;
		}

		amtp = (pin_decimal_t *)PIN_FLIST_FLD_GET(flistp, 
			PIN_FLD_AMOUNT, 1, ebufp);
		cmdp = (pin_charge_cmd_t *)PIN_FLIST_FLD_GET(flistp,
			PIN_FLD_COMMAND, 0, ebufp);
		a_pdp = (poid_t *)PIN_FLIST_FLD_GET(flistp, 
			PIN_FLD_ACCOUNT_OBJ,0,ebufp);
		selectp = (int *)PIN_FLIST_FLD_GET(flistp,
			PIN_FLD_SELECT_RESULT, 1, ebufp);

		/***************************************************
		 * Did PCM_OP_PYMT_SELECT_ITEMS retured OK?
		 ***************************************************/
		if (selectp && (*selectp != PIN_SELECT_RESULT_PASS)){
			result = PIN_CHARGE_RES_FAIL_SELECT_ITEMS;
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, 
				(void *)&result, ebufp);

			descr = "Select Items Failed";
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, 
				(void *)descr, ebufp);

			continue;
		}

		/***************************************************
		 * Get the amount for this charge. If the amount to
		 * be charged is 0.0, then don't even bother dealing
		 * with this element.
		 ***************************************************/
		if ((amtp && 
			pbo_decimal_compare(amtp, minimum_pay, ebufp) < 0) &&
			 (cmdp &&  ((*cmdp == PIN_CHARGE_CMD_CONDITION) ||
			(*cmdp == PIN_CHARGE_CMD_AUTH_ONLY) ||
			(*cmdp == PIN_CHARGE_CMD_DEPOSIT)))) {
			result = PIN_CHARGE_RES_FAIL_NO_MIN;
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, 
				(void *)&result, ebufp);

			descr = "Below Minimum";
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, 
				(void *)descr, ebufp);

			continue;
		}

		/***************************************************
		 * Set the minimum refund to compare.
		 ***************************************************/
		if (cmdp && ((*cmdp == PIN_CHARGE_CMD_NONE) &&
			(pbo_decimal_sign(amtp, ebufp) < 0))) {

			pbo_decimal_negate_assign(minimum_ref, ebufp);
		}

		/***************************************************
		 * If command and amount are not NULL and if the
		 * command is refund or if the commnd is none, but
		 * has a negative amount, check the amount with
		 * the minimum refund. 
		 ***************************************************/
		if (cmdp && amtp && (((*cmdp == PIN_CHARGE_CMD_REFUND) &&
			(pbo_decimal_compare(amtp, minimum_ref, ebufp) < 0)) ||
			((*cmdp == PIN_CHARGE_CMD_NONE) && 
			(pbo_decimal_sign(amtp, ebufp) < 0) &&
			(pbo_decimal_compare(amtp, minimum_ref, ebufp) > 0)))) {

			result = PIN_CHARGE_RES_FAIL_NO_MIN;
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, 
					(void *)&result, ebufp);

			descr = "Below Minimum";
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, 
					(void *)descr, ebufp);

			continue;
		}

		/***************************************************
		 * If command and amount are not NULL and if the
		 * command is REFUND or if the command is NONE and
		 * its a negative amount, make sure that the account
		 * has sufficient credit balance. If not, set the 
		 * RESULT code to be NO_CREDIT_BALANCE.
		 ***************************************************/
		if (cmdp && amtp && ((*cmdp == PIN_CHARGE_CMD_REFUND) ||
			((*cmdp == PIN_CHARGE_CMD_NONE) && 
			(pbo_decimal_sign(amtp, ebufp) < 0)))) {

			flag = fm_pymt_pol_pre_collect_validate_refund(ctxp,
					amtp, flistp, ebufp);
			if (flag == PIN_BOOLEAN_FALSE) {

				result = PIN_CHARGE_RES_NO_CREDIT_BALANCE;
				PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, 
						(void *)&result, ebufp);

				descr = "No credit available";
				PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, 
						(void *)descr, ebufp);
			}
		}

		/***************************************************
		 * Is there a outstanding checkpoint for this acct?
		 ***************************************************/
		if ((chkpt_flistp != (pin_flist_t *)NULL) && cmdp &&
			((*cmdp == PIN_CHARGE_CMD_CONDITION) ||
			(*cmdp == PIN_CHARGE_CMD_REFUND) ||
			(*cmdp == PIN_CHARGE_CMD_AUTH_ONLY) ||
			(*cmdp == PIN_CHARGE_CMD_DEPOSIT))) {

			if (fm_pymt_pol_is_chkpt_outstanding(a_pdp,
				chkpt_flistp, ebufp)) {

				result = PIN_CHARGE_RES_CHECKPOINT;
				PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, 
					(void *)&result, ebufp);

				descr = "Checkpoint Outstanding";
				PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, 
					(void *)descr, ebufp);

				continue;
			}
		}
		s_flistp = PIN_FLIST_CREATE(ebufp);
		vp = PIN_FLIST_FLD_GET(flistp, PIN_FLD_ACH, 1, ebufp);
		if (vp) {
			vp = PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_POID, 0,
								 ebufp);
			PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_POID, 
						vp, ebufp);
			vp = PIN_FLIST_FLD_GET(flistp, PIN_FLD_ACH, 0,
                                                                 ebufp);	
			if (vp) {
				rec_id = *(int32 *)vp;
			}
			PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_ACH, 
						&rec_id, ebufp);

		        PCM_OP(ctxp, PCM_OP_PYMT_GET_ACH_INFO, sflag,
					s_flistp, &r_flistp, ebufp);

			rc_flistp = PIN_FLIST_ELEM_GET(r_flistp, PIN_FLD_RESULTS,
								 0, 0, ebufp);
			vp = PIN_FLIST_FLD_GET(rc_flistp,
       		                 		PIN_FLD_NAME, 0, ebufp);
			memset(vendor_name, 0, sizeof(vendor_name));
			if ((vp != (void *)NULL) && strlen(vp)) {
				strcpy(vendor_name, (char *)vp);
			}
		}
		 PIN_FLIST_DESTROY_EX(&s_flistp, NULL);
                 PIN_FLIST_DESTROY_EX(&r_flistp, NULL);

		/*************************************************************
		 * If Bertelsmann then check the mandate status.
		 *************************************************************/
		if (dd_vendorp && !strcasecmp(dd_vendorp,
			"Bertelsmann") && cmdp && *cmdp != PIN_CHARGE_CMD_RFR 
			&& vendor_name && !strcasecmp(vendor_name, 
			"bertelsmann")) {

			s_flistp = PIN_FLIST_CREATE(ebufp);
			s_pdp = PIN_POID_CREATE(PIN_POID_GET_DB(a_pdp),
				"/search/pin", 0, ebufp);
			PIN_FLIST_FLD_PUT(s_flistp, PIN_FLD_POID, 
						(void *)s_pdp, ebufp);
			PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_FLAGS, 
						(void *)&sflag, ebufp);
		
			PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_TEMPLATE, 
				"select X from /payinfo where F1 = V1 ", ebufp);

			a_flistp = PIN_FLIST_ELEM_ADD(s_flistp, PIN_FLD_ARGS, 
								1, ebufp);
			PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_ACCOUNT_OBJ, 
								a_pdp, ebufp);

			a_flistp = PIN_FLIST_ELEM_ADD(s_flistp, 
						PIN_FLD_RESULTS, 0, ebufp);
			b_flistp = PIN_FLIST_ELEM_ADD(a_flistp, 
						PIN_FLD_DD_INFO, 0, ebufp);
			PIN_FLIST_FLD_SET(b_flistp, PIN_FLD_MANDATE_STATUS, 
							(void *)0, ebufp);
			
			PCM_OP(ctxp, PCM_OP_SEARCH, 0, s_flistp, &r_flistp, 
									ebufp);

			if (r_flistp != (pin_flist_t *)NULL) {
				a_flistp = PIN_FLIST_ELEM_GET(r_flistp, 
						PIN_FLD_RESULTS, 0, 1, ebufp);
				b_flistp = PIN_FLIST_ELEM_GET(a_flistp, 
						PIN_FLD_DD_INFO, 0, 1, ebufp);

				/***********************************************
			 	* Do not allow accounts with the following
			 	* mandate_statuses to go to collection.
			 	***********************************************/
				mandate_status = PIN_FLIST_FLD_GET(b_flistp, 
						PIN_FLD_MANDATE_STATUS, 1, ebufp);
			
				if (!mandate_status || 
				   ((*mandate_status != PIN_MANDATE_RECEIVED) &&
				   (*mandate_status != PIN_MANDATE_NOT_REQUIRED)))
				{
					result = PIN_CHARGE_RES_FAIL_SELECT_ITEMS;
					PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, 
						(void *)&result, ebufp);

					descr = "Mandate Outstanding";
					PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, 
						(void *)descr, ebufp);
				}
			}

			/***********************************************
			 * Clean up.
			 ***********************************************/
			PIN_FLIST_DESTROY_EX(&s_flistp, NULL);
			PIN_FLIST_DESTROY_EX(&r_flistp, NULL);
		}

		/***************************************************
		 * Check the command for this element.
		 ***************************************************/
		if (cmdp == NULL) {
			pin_set_err(ebufp, PIN_ERRLOC_FM,
				PIN_ERRCLASS_APPLICATION, 
				PIN_ERR_MISSING_ARG,
				PIN_FLD_COMMAND, elemid, 0);

			continue;
		}

		/***************************************************
		 * Is it ok?
		 ***************************************************/

		switch (*cmdp) {
		case PIN_CHARGE_CMD_NONE:
		case PIN_CHARGE_CMD_AUTH_ONLY:
		case PIN_CHARGE_CMD_CONDITION:
		case PIN_CHARGE_CMD_DEPOSIT:
		case PIN_CHARGE_CMD_REFUND:
		case PIN_CHARGE_CMD_RFR:
		case PIN_CHARGE_CMD_RESUBMIT:
			break;
		default:
			result = PIN_CHARGE_RES_INVALID_CMD;
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, 
				(void *)&result, ebufp);

			descr = "Invalid Command";
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, 
				(void *)descr, ebufp);
		}
	}

	/***********************************************************
	 * Clean up.
	 ***********************************************************/
	PIN_FLIST_DESTROY_EX(&chkpt_flistp, NULL);
	pbo_decimal_destroy(&minimum_pay);
	pbo_decimal_destroy(&minimum_ref);

	if (dd_vendorp != (char *)NULL) {
		free(dd_vendorp);
		dd_vendorp = NULL;
	}

	/***********************************************************
	 * Results.
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_FLIST_DESTROY_EX(&c_flistp, NULL);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_pymt_pol_pre_collect error", ebufp);
	} else {
		*ret_flistpp = c_flistp;
		PIN_ERR_CLEAR_ERR(ebufp);
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_pymt_pol_pre_collect return flist", 
			*ret_flistpp);
	}

	return;
}
/*******************************************************************
 * This function gets pending items to be included in the Bill.
 *******************************************************************/
static void 
fm_bill_pol_get_pending_items(
	pcm_context_t		*ctxp,
	pin_flist_t		*i_flistp, 
	pin_flist_t		**r_flistpp,
	pin_errbuf_t		*ebufp)
{
	pin_flist_t	*s_flistp = NULL;
	pin_flist_t	*temp_flistp = NULL;
	pin_flist_t	*o_flistp = NULL;
	pin_cookie_t	cookie = NULL;
	poid_t		*s_pdp = NULL;
	poid_t		*bi_pdp = NULL;
	poid_t		*acc_pdp = NULL;
	poid_t		*srv_pdp = NULL;
	poid_t		*srv_pdp1 = NULL;
	int32		rec_id = 0;
	int32		s_flags = 0;
	void		*vp = NULL;
	int64		database = 0;
	int32		status = 0;
	int		srv_cnt = 0;
	int		first_srv_flag = 0;
	char		s_template[BUFSIZ] = {0};
	char		tmp_s_template[BUFSIZ] = {0};

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/**************************************************************
	 * Check whether the input flist contains the list of pendning
	 * items. If so, prepare output flist for the policy, and return
	 **************************************************************/
	if (PIN_FLIST_ELEM_GET_NEXT(i_flistp, PIN_FLD_ITEMS,
						&rec_id, 1, &cookie, ebufp)) {
		fm_bill_pol_prepare_pending_items(ctxp, i_flistp, r_flistpp,
							ebufp);
		return;
	}

	/*********************************************************
	 * Get billinfo poid
	 *********************************************************/
	bi_pdp = (poid_t *)PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_BILLINFO_OBJ, 0,
									ebufp);
	/*********************************************************
	 * Get account poid
	 *********************************************************/
	acc_pdp = (poid_t *)PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_POID, 0,
								  ebufp);
	/*********************************************************
	 * Create the search flist to search for the item objects
	 *********************************************************/
	s_flistp = PIN_FLIST_CREATE(ebufp);

	database = pin_poid_get_db(bi_pdp);
	s_pdp = (poid_t *)PIN_POID_CREATE(database, "/search", -1, ebufp);
	PIN_FLIST_FLD_PUT(s_flistp, PIN_FLD_POID, (void *)s_pdp, ebufp);
	PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_FLAGS, (void *)&s_flags, ebufp);

        /***********************************************************
         * Start with the base search template. Add the search for list of
	 * services if they are presented in the input flist.
         ***********************************************************/
        strcpy(s_template, "select X from /item where F1 = V1 and F2 = V2 ");

	srv_pdp = (poid_t *)PIN_FLIST_FLD_GET(i_flistp, 
						PIN_FLD_SERVICE_OBJ, 1, ebufp);
	if (srv_pdp) {
		/***********************************************
		 * Get all services from the service group
		 ***********************************************/
		fm_utils_bill_get_service_group(ctxp, srv_pdp,acc_pdp,&o_flistp,
									ebufp);
		/***********************************************************
		 * Different 'where' clauses will be used depending on 
		 * whether the services array contains a single service or 
		 * multiple ones.
		 ***********************************************************/
		srv_cnt = PIN_FLIST_ELEM_COUNT(o_flistp, PIN_FLD_SERVICES, 
									ebufp);

		if (1 == srv_cnt) {
			strncpy(tmp_s_template, s_template,
				sizeof(tmp_s_template)-1);
			pin_snprintf(s_template, sizeof(s_template), "%s %s",
				tmp_s_template, "and F3 = V3");
			cookie = NULL;
			temp_flistp = PIN_FLIST_ELEM_GET_NEXT(o_flistp, 
						PIN_FLD_SERVICES, &rec_id, 0, 
						&cookie, ebufp);
			srv_pdp1 = (poid_t *)PIN_FLIST_FLD_GET(temp_flistp, 
						PIN_FLD_SERVICE_OBJ, 0, ebufp);
			/* Add ARG 3 - SERVICE_OBJ */
			temp_flistp = PIN_FLIST_ELEM_ADD(s_flistp,PIN_FLD_ARGS,
								3, ebufp);
			PIN_FLIST_FLD_SET(temp_flistp,
				PIN_FLD_SERVICE_OBJ, (void *)srv_pdp1, ebufp);
		} else { /* Multiple services */

			/******************************************************
			 * SEARCH CONDITION:  service_obj_id0 in 
			 * (poid_id_1, poid_id_2, ...  poid_id_n)
			 *****************************************************/

			/******************************************************
			 * Append the initial part of 'in' clause to search 
			 * template 
			 *****************************************************/
			strncpy(tmp_s_template, s_template,
				sizeof(tmp_s_template)-1);	
			pin_snprintf(s_template, sizeof(s_template), "%s %s",
				tmp_s_template, "and service_obj_id0 in (");

			cookie = NULL;
			while ((temp_flistp = PIN_FLIST_ELEM_GET_NEXT(o_flistp,
				PIN_FLD_SERVICES, &rec_id, 1, &cookie, ebufp))) {

				vp = (poid_t *)PIN_FLIST_FLD_GET(temp_flistp, 
						PIN_FLD_SERVICE_OBJ, 0, ebufp);

				if (first_srv_flag == 0) { /* First iteration */
					/*************************************
					 * NOTE: NO 'comma' before first poid ID
					 * in 'in' clause 
					 *************************************/
					first_srv_flag = 1;
				}
				else { /* NOT the first iteration */
					/*************************************
					 * Add 'comma' before adding this poid 
					 * ID to 'in' clause 
					 ************************************/
					strncpy(tmp_s_template, s_template,
						sizeof(tmp_s_template)-1);
					pin_snprintf(s_template, sizeof(s_template),
						"%s%s", tmp_s_template, ", ");
				}

				/* Add this poid ID to 'in' clause */
				strncpy(tmp_s_template, s_template,
					sizeof(tmp_s_template)-1);
				pin_snprintf(s_template, sizeof(s_template), 
					"%s%" I64_PRINTF_PATTERN "d",
					tmp_s_template, 
					PIN_POID_GET_ID((poid_t *)vp));
				}

			/*************************************
                	 * Append the last part of 'in' clause 
			 * to search template 
			 ************************************/
               		strncpy(tmp_s_template, s_template,
				sizeof(tmp_s_template)-1); 
			pin_snprintf(s_template, sizeof(s_template), "%s%s",
				tmp_s_template, ")");

        	} /* end else (multiple services) */
	}

	PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_TEMPLATE, (void *)s_template, 
									ebufp);
	/*********************************************************
	 * Add the search arguments. This is a 2 arg =, = search
	 *********************************************************/
	temp_flistp = PIN_FLIST_ELEM_ADD(s_flistp, PIN_FLD_ARGS, 1, ebufp);
	PIN_FLIST_FLD_SET(temp_flistp, PIN_FLD_BILLINFO_OBJ, (void *)bi_pdp,
			ebufp);

	status = PIN_ITEM_STATUS_PENDING;
	temp_flistp = PIN_FLIST_ELEM_ADD(s_flistp, PIN_FLD_ARGS, 2, ebufp);
	PIN_FLIST_FLD_SET(temp_flistp, PIN_FLD_STATUS, (void *)&status, ebufp);

	/*********************************************************
	 * Add the results array for the search.
	 *********************************************************/
	temp_flistp = PIN_FLIST_ELEM_ADD(s_flistp, PIN_FLD_RESULTS, 0, ebufp);
	PIN_FLIST_FLD_SET(temp_flistp, PIN_FLD_POID, NULL, ebufp);
	PIN_FLIST_FLD_SET(temp_flistp, PIN_FLD_ITEM_TOTAL, NULL, ebufp);
	PIN_FLIST_FLD_SET(temp_flistp, PIN_FLD_ADJUSTED, NULL, ebufp);
	PIN_FLIST_FLD_SET(temp_flistp, PIN_FLD_DISPUTED, NULL, ebufp);
	PIN_FLIST_FLD_SET(temp_flistp, PIN_FLD_WRITEOFF, NULL, ebufp);
	PIN_FLIST_FLD_SET(temp_flistp, PIN_FLD_RECVD, NULL, ebufp);
	PIN_FLIST_FLD_SET(temp_flistp, PIN_FLD_TRANSFERED, NULL, ebufp);
	PIN_FLIST_FLD_SET(temp_flistp, PIN_FLD_SERVICE_OBJ, NULL, ebufp);
	PIN_FLIST_FLD_SET(temp_flistp, PIN_FLD_BILL_OBJ, NULL, ebufp);

	/**********************************************************
	 * do real search
	 **********************************************************/
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
                       "fm_bill_pol_get_pending_items search flist", s_flistp);
	PCM_OP(ctxp, PCM_OP_SEARCH, 0, s_flistp, r_flistpp, ebufp);


	PIN_FLIST_DESTROY_EX(&s_flistp, NULL);
	PIN_FLIST_DESTROY_EX(&o_flistp, NULL);

	/********************************************************* 
	 * Errors..?
	 *********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_bill_pol_get_pending_items error",ebufp);
	}
	return;
}
Пример #19
0
/*******************************************************************
 * Multi search.
 *
 *	Performs a read-fields search to get the poid, merchant
 *	and status of all non-billable accounts in the database.
 *	We walk	the results array and display each individually.
 *
 *	The "one arg equal" search for /account is 201.
 *
 *******************************************************************/
void
sample_read_flds_search(
	pcm_context_t	*ctxp,
	u_int64		database,
	pin_errbuf_t	*ebufp)
{
	pin_cookie_t	cookie = NULL;
	pin_flist_t	*flistp = NULL;
	pin_flist_t	*a_flistp = NULL;
	pin_flist_t	*r_flistp = NULL;

	poid_t		*objp = NULL;
	u_int64		id;
	u_int		vp;
	int32		rec_id;

	/***********************************************************
	 * Check the error buffer.
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Allocate the flist for searching.
	 ***********************************************************/
	flistp = PIN_FLIST_CREATE(ebufp);

	/***********************************************************
	 * Allocate the search poid and give it to the flist.
	 ***********************************************************/
	id = (u_int64)201;

	objp = PIN_POID_CREATE(database, "/search", id, ebufp);
	PIN_FLIST_FLD_PUT(flistp, PIN_FLD_POID, (void *)objp, ebufp);

	/***********************************************************
	 * Add a search arguments array.
	 ***********************************************************/
	a_flistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 1, ebufp);

	/***********************************************************
	 * Add non-billable (= undefined) as the argument.
	 ***********************************************************/
	vp = PIN_BILL_TYPE_UNDEFINED;
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_BILL_TYPE, (void *)&vp, ebufp);

	/***********************************************************
	 * Add a search results array.
	 ***********************************************************/
	a_flistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_RESULTS, 0, ebufp);

	/***********************************************************
	 * Add markers for the fields we want to read.
	 ***********************************************************/
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_POID, (void *)NULL, ebufp);
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_MERCHANT, (void *)NULL, ebufp);
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_STATUS, (void *)NULL, ebufp);

	/***********************************************************
	 * Call the DM to do the search.
	 ***********************************************************/
	PCM_OP(ctxp, PCM_OP_SEARCH, 0, flistp, &r_flistp, ebufp);

	/***********************************************************
	 * Walk the results array.
	 ***********************************************************/
	a_flistp = PIN_FLIST_ELEM_GET_NEXT(r_flistp, PIN_FLD_RESULTS,
		&rec_id, 1, &cookie, ebufp);
	while (a_flistp != (pin_flist_t *)NULL) {

		/***************************************************
		 * Show this result.
		 ***************************************************/
		fprintf(stdout,"\nMulti Search Result(%d) Flist:\n", rec_id);
		PIN_FLIST_PRINT(a_flistp, stdout, ebufp);

		/***************************************************
		 * Get the next result.
		 ***************************************************/
		a_flistp = PIN_FLIST_ELEM_GET_NEXT(r_flistp,
			PIN_FLD_RESULTS, &rec_id, 1, &cookie, ebufp);
	}

	/***********************************************************
	 * Clean up.
	 ***********************************************************/
	/* Free local memory */
	PIN_FLIST_DESTROY(r_flistp, NULL);
	PIN_FLIST_DESTROY(flistp, NULL);

	/* Error? */
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"sample_read_flds_search error", ebufp);
	}

	return;
}
/********************************************************************
 * fm_cust_pol_get_poplist()
 *
 *	Obtains a list of pops and adds to the given outflistp.
 *	If no PIN_FLD_ANI is found on the input flist, then the
 *	entire pop list is returned.  Otherwise, only the POP
 *	matching the ANI is returned. 
 *
 ********************************************************************/
static void
fm_cust_pol_get_poplist(
	pcm_context_t	*ctxp,			/* Connection context	*/
	pin_flist_t	*in_flistp,		/* Client's input flist */
	pin_flist_t	*out_flistp,		/* Search results flist */
	pin_errbuf_t	*ebufp)			/* Error buff		*/
{
	u_int64 	database;		/* Requested database 	*/
	poid_t		*poidp = NULL;		/* Input poid		*/
	poid_t		*objp = NULL;		/* New search poid	*/
	poid_t		*type_poidp;		/* Used for full poplist*/
	pin_cookie_t    cookie = NULL;  	/* For getting results	*/
	pin_cookie_t    cookie2 = NULL;  	/* For getting anis	*/
	pin_flist_t	*flistp = NULL;		/* Search flist created	*/
        pin_flist_t	*ani_flistp = NULL;	/* ANI array flist	*/
	pin_flist_t	*a_flistp = NULL;	/* New element pointer	*/
	pin_flist_t	*e_flistp = NULL;	/* Element ptr 4 pop arr*/
	pin_flist_t	*r_flistp = NULL;	/* Search return flist	*/
	pin_flist_t	*sort_flistp = NULL;	/* Sort flist		*/
	u_int64         id;			/* Search id 		*/
	u_int		type = POP_PRIMARY;	/* Only return prime pop*/ 
	int32           rec_id;         	/* PIN_FLD_RESULTS elem	*/
	int32           rec_id2;         	/* ANI results elem	*/
	void		*vp;			/* PIN_FLD_ANI value	*/
	void		*vp2;			/* Returned fields ptr	*/

	/***********************************************************
         * Check the error buffer.
         ***********************************************************/
        if (PIN_ERR_IS_ERR(ebufp))
                return;
        PIN_ERR_CLEAR_ERR(ebufp);

        /***********************************************************
         * Allocate the flist for searching.
         ***********************************************************/
        flistp = PIN_FLIST_CREATE(ebufp);

        /***********************************************************
         * Get the database number.
         ***********************************************************/
	poidp = (poid_t *)PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_POID, 0, ebufp);
	database = PIN_POID_GET_DB(poidp);

        /***********************************************************
         * Allocate the search poid and give it to the flist.  Use
	 * the 2 arg search id if args are found, otherwise use
	 * the 1 arg search which returns all the pops ordered.
         ***********************************************************/
       	vp = PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_ANI, 1, ebufp);
	if (vp == NULL) {
		id = (u_int64)300;
	} else {
		id = (u_int64)301;
	}
        objp = PIN_POID_CREATE(database, "/search/pin", id, ebufp);
        PIN_FLIST_FLD_PUT(flistp, PIN_FLD_POID, (void *)objp, ebufp);

        /***********************************************************
         * Add a search arguments array.
         ***********************************************************/
        a_flistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 1, ebufp);

        /***********************************************************
         * Determine whether the entire poplist should be returned
	 * or an ani to pop match should be done.  The rule is if
	 * there's a PIN_FLD_ANI field, return the entire list,
 	 * otherwise, do a ani to pop match but only return the
	 * primary one.
         ***********************************************************/
        type_poidp = PIN_POID_CREATE(database, "/pop", (int64)-1, ebufp);
	if (vp == NULL) {
		PIN_FLIST_FLD_PUT(a_flistp, PIN_FLD_POID,
			(void *)type_poidp, ebufp);
	} else {
        	/*
         	** 2 arg search, return pop that matches ani and is a
		** primary pop.
         	*/
        	ani_flistp = PIN_FLIST_CREATE(ebufp);
		/*
		** PIN_FLD_ANI for our first arg.
		*/
		PIN_FLIST_FLD_SET(ani_flistp, PIN_FLD_ANI, vp, ebufp );
		PIN_FLIST_ELEM_SET(a_flistp, ani_flistp, PIN_FLD_ANIS,
                	0, ebufp );
		/*
		** PIN_FLD_TYPE for our second arg.
		*/
		a_flistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 2, ebufp);
        	ani_flistp = PIN_FLIST_CREATE(ebufp);
		PIN_FLIST_FLD_SET(ani_flistp, PIN_FLD_TYPE, 
			(void *)&type, ebufp);
		PIN_FLIST_ELEM_SET(a_flistp, ani_flistp, PIN_FLD_ANIS, 1,
			ebufp);
	}

        /***********************************************************
         * Put on the PIN_FLD_RESULTS array for our results.
         ***********************************************************/
        a_flistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_RESULTS, 0, ebufp);
	/*
	** Return the pop, city, state and zip fields if the entire poplist 
	** was requested, otherwise return the same fields including
	** the flags if pop matching was requested.
	*/
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_PHONE, (void *)NULL, ebufp); 
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_CITY, (void *)NULL, ebufp); 
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_STATE, (void *)NULL, ebufp); 
	PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_ZIP, (void *)NULL, ebufp); 
	if (vp != NULL) {
		/*
		** Add the ANIS array if PIN_FLD_ANI arg was passed in.
		*/
        	ani_flistp = PIN_FLIST_CREATE(ebufp);
		PIN_FLIST_FLD_SET(ani_flistp, PIN_FLD_ANI, 
			(void *)NULL, ebufp);
		PIN_FLIST_FLD_SET(ani_flistp, PIN_FLD_TYPE, 
			(void *)NULL, ebufp);
		PIN_FLIST_FLD_SET(ani_flistp, PIN_FLD_FLAGS, 
			(void *)NULL, ebufp);
		PIN_FLIST_ELEM_SET(a_flistp, ani_flistp, PIN_FLD_ANIS, 0,
			ebufp);
	}
	
        /***********************************************************
         * Call the DM to do the search.
         ***********************************************************/
        PCM_OP(ctxp, PCM_OP_SEARCH, 0, flistp, &r_flistp, ebufp);

	/***********************************************************
         * Walk the search results array adding each to the
	 * PIN_FLD_POP's array flist to pass back to the caller. 
         ***********************************************************/
        a_flistp = PIN_FLIST_ELEM_GET_NEXT(r_flistp, PIN_FLD_RESULTS,
                &rec_id, 1, &cookie, ebufp);
	while (a_flistp != (pin_flist_t *)NULL) {

        	e_flistp = PIN_FLIST_ELEM_ADD(out_flistp, PIN_FLD_POP, 
			rec_id, ebufp);

		/*
		** Take the PIN_FLD_PHONE and put it on the PIN_FLD_POP array.
		*/
		vp2 = PIN_FLIST_FLD_TAKE(a_flistp, PIN_FLD_PHONE, 0, ebufp);
		PIN_FLIST_FLD_PUT(e_flistp, PIN_FLD_PHONE, vp2, ebufp);
		/*
		** Take the PIN_FLD_CITY and put it on the PIN_FLD_POP array.
		*/
		vp2 = PIN_FLIST_FLD_TAKE(a_flistp, PIN_FLD_CITY, 0, ebufp);
		PIN_FLIST_FLD_PUT(e_flistp, PIN_FLD_CITY, vp2, ebufp);
		/*
		** Take the PIN_FLD_STATE and put it on the PIN_FLD_POP array.
		*/
		vp2 = PIN_FLIST_FLD_TAKE(a_flistp, PIN_FLD_STATE, 0, ebufp);
		PIN_FLIST_FLD_PUT(e_flistp, PIN_FLD_STATE, vp2, ebufp);
		/*
		** Take the PIN_FLD_ZIP and put it on the PIN_FLD_POP array.
		*/
		vp2 = PIN_FLIST_FLD_TAKE(a_flistp, PIN_FLD_ZIP, 0, ebufp);
		PIN_FLIST_FLD_PUT(e_flistp, PIN_FLD_ZIP, vp2, ebufp);
		/*
		** Walk the ani array (if we're pop matching) to get the 
		** PIN_FLD_FLAGS field, should only be one.
		*/
		if (vp != NULL) {
			ani_flistp = (pin_flist_t *)NULL;
			ani_flistp = PIN_FLIST_ELEM_GET_NEXT(a_flistp, 
				PIN_FLD_ANIS, &rec_id2, 0, &cookie2, ebufp);
			while (ani_flistp != (pin_flist_t *)NULL) {
				vp2 = PIN_FLIST_FLD_TAKE(ani_flistp, 
					PIN_FLD_FLAGS, 0, ebufp);
				PIN_FLIST_FLD_PUT(e_flistp, PIN_FLD_FLAGS, 
					vp2, ebufp);
				ani_flistp = PIN_FLIST_ELEM_GET_NEXT(a_flistp,
					PIN_FLD_ANIS, &rec_id2, 1, &cookie2, 
					ebufp);
			}
		}

		/***************************************************
                 * Get the next result.
                 ***************************************************/
                a_flistp = PIN_FLIST_ELEM_GET_NEXT(r_flistp,
                        PIN_FLD_RESULTS, &rec_id, 1, &cookie, ebufp);
	}

        /***********************************************************
         * Clean up.
         ***********************************************************/
	PIN_FLIST_DESTROY(flistp, NULL);
	PIN_FLIST_DESTROY(r_flistp, NULL);

        if (PIN_ERR_IS_ERR(ebufp)) {
                PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_cust_pol_read_poplist error", ebufp);
        }

        return;
}	/* fm_cust_pol_read_poplist */
Пример #21
0
/*******************************************************************
 * Simple search.
 *
 *	Performs a read-object search for the master account
 *	object and displays the results with PIN_FLIST_PRINT.
 *
 *	The "one arg equal" search for /account is 201.
 *
 *	Note: In real life, this isn't particularly useful
 *	since we could use the poid of the account to do a
 *	read-object op directly.
 *
 *******************************************************************/
void
sample_read_obj_search(
	pcm_context_t	*ctxp,
	u_int64		database,
	pin_errbuf_t	*ebufp)
{
	pin_flist_t	*flistp = NULL;
	pin_flist_t	*a_flistp = NULL;
	pin_flist_t	*r_flistp = NULL;

	poid_t		*objp = NULL;
	u_int64		id;


	/***********************************************************
	 * Check the error buffer.
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Allocate the flist for searching.
	 ***********************************************************/
	flistp = PIN_FLIST_CREATE(ebufp);

	/***********************************************************
	 * Allocate the search poid and give it to the flist.
	 ***********************************************************/
	id = (u_int64)201;

	objp = PIN_POID_CREATE(database, "/search", id, ebufp);
	PIN_FLIST_FLD_PUT(flistp, PIN_FLD_POID, (void *)objp, ebufp);

	/***********************************************************
	 * Add a search arguments array.
	 ***********************************************************/
	a_flistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 1, ebufp);

	/***********************************************************
	 * Allocate the master account poid and add as the arg.
	 ***********************************************************/
	id = (u_int64)1;

	objp = PIN_POID_CREATE(database, "/account", id, ebufp);
	PIN_FLIST_FLD_PUT(a_flistp, PIN_FLD_POID, (void *)objp, ebufp);

	/***********************************************************
	 * Add a search results marker.
	 *
	 * Making this NULL forces the read-object result we want.
	 ***********************************************************/
	a_flistp = (pin_flist_t *)NULL;
	PIN_FLIST_ELEM_PUT(flistp, a_flistp, PIN_FLD_RESULTS, 0, ebufp);

	/***********************************************************
	 * Call the DM to do the search.
	 ***********************************************************/
	PCM_OP(ctxp, PCM_OP_SEARCH, 0, flistp, &r_flistp, ebufp);

	/***********************************************************
	 * Get (and show) the results.
	 ***********************************************************/
	a_flistp = PIN_FLIST_ELEM_GET(r_flistp, PIN_FLD_RESULTS, 0, 0, ebufp);

	fprintf(stdout,"\nSimple Search Result Flist:\n");
	PIN_FLIST_PRINT(a_flistp, stdout, ebufp);

	/***********************************************************
	 * Clean up.
	 ***********************************************************/
	/* Free local memory */
	PIN_FLIST_DESTROY(r_flistp, NULL);
	PIN_FLIST_DESTROY(flistp, NULL);

	/* Error? */
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"sample_read_obj_search error", ebufp);
	}

	return;
}
static void
fm_pymt_pol_spec_collect_get_items(
        pcm_context_t   *ctxp,
        int32           flags,
        pin_flist_t     *i_flistp,
        pin_flist_t     *o_flistp,
        pin_errbuf_t    *ebufp)
{
        pin_flist_t     *items_flistp = NULL;
        pin_flist_t     *r_flistp = NULL;
        pin_flist_t     *flistp = NULL;
        poid_t          *s_pdp = NULL;
        poid_t          *bi_pdp = NULL;
        int32           status = 0;
        int64           database = 0;
        int32           sflags = SRCH_DISTINCT;
        int32           result = PIN_BOOLEAN_FALSE;
        void            *vp = NULL;
        pin_decimal_t   *zero_decimal =  pin_decimal("0.0", ebufp);

        if (PIN_ERR_IS_ERR(ebufp)) {
                return;
        }
        PIN_ERR_CLEAR_ERR(ebufp);

        /*********************************************************
         * Get the ACH details.
         *********************************************************/
        fm_pymt_pol_spec_collect_get_ach(ctxp, flags, i_flistp,
                                                o_flistp, ebufp);

        bi_pdp = PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_BILLINFO_OBJ, 0, ebufp);

        /*********************************************************
         * Create the search flist to search in the item objects
         *********************************************************/
        items_flistp = PIN_FLIST_CREATE(ebufp);
        database = PIN_POID_GET_DB(bi_pdp);
        s_pdp = PIN_POID_CREATE(database, "/search", -1, ebufp);
        PIN_FLIST_FLD_PUT(items_flistp, PIN_FLD_POID, (void *)s_pdp, ebufp);
        PIN_FLIST_FLD_SET(items_flistp, PIN_FLD_TEMPLATE,
         (void *) "select X from /item where F1 = V1 and ( F2 = V2 or F3 = V3 )" \
                " and F4 != V4 order by F5 ", ebufp);
        PIN_FLIST_FLD_SET(items_flistp, PIN_FLD_FLAGS, (void *)&sflags, ebufp);

        /*********************************************************
         * Add the search arguments.
         *********************************************************/
        flistp = PIN_FLIST_ELEM_ADD(items_flistp, PIN_FLD_ARGS, 1, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_AR_BILLINFO_OBJ, (void *)bi_pdp,
                                                                ebufp);

        status = PIN_ITEM_STATUS_PENDING;
        flistp = PIN_FLIST_ELEM_ADD(items_flistp, PIN_FLD_ARGS, 2, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_STATUS, (void *)&status, ebufp);

        status = PIN_ITEM_STATUS_OPEN;
        flistp = PIN_FLIST_ELEM_ADD(items_flistp, PIN_FLD_ARGS, 3, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_STATUS, (void *)&status, ebufp);

        flistp = PIN_FLIST_ELEM_ADD(items_flistp, PIN_FLD_ARGS, 4, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_DUE, (void *)zero_decimal, ebufp);

        flistp = PIN_FLIST_ELEM_ADD(items_flistp, PIN_FLD_ARGS, 5, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_EFFECTIVE_T, (void *)NULL, ebufp);

        /*********************************************************
         * Add the results array for the search.
         *********************************************************/

        flistp = PIN_FLIST_ELEM_ADD(items_flistp, PIN_FLD_RESULTS, 0, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_POID,(void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_BILL_OBJ, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_AR_BILL_OBJ, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_ACCOUNT_OBJ, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_DUE,(void *) NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_EFFECTIVE_T, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_ITEM_TOTAL, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_DISPUTED, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_RECVD, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_ADJUSTED, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_TRANSFERED, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_CURRENCY, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_STATUS, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_ITEM_NO, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_BILLINFO_OBJ, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_AR_BILLINFO_OBJ, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_SERVICE_OBJ, (void *)NULL, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_EVENT_POID_LIST, (void *)NULL, ebufp);

        /**********************************************************
         * search ALL Open and Pending items
         **********************************************************/
        PCM_OP(ctxp, PCM_OP_SEARCH,
                PCM_OPFLG_READ_UNCOMMITTED , items_flistp, &r_flistp,ebufp);

        if (PIN_FLIST_FLD_COPY(r_flistp, PIN_FLD_RESULTS, o_flistp,
                PIN_FLD_ITEMS, ebufp) == 1) {
                result = PIN_BOOLEAN_TRUE;
        }

        PIN_FLIST_FLD_SET(o_flistp, PIN_FLD_BOOLEAN, (void *)&result, ebufp);

        /*********************************************************
         * Cleanup...
         *********************************************************/
        PIN_FLIST_DESTROY_EX(&items_flistp, NULL);
        PIN_FLIST_DESTROY_EX(&r_flistp, NULL);
        PIN_DECIMAL_DESTROY_EX(&zero_decimal);

        /*********************************************************
         * Errors..?
         *********************************************************/
        if (PIN_ERR_IS_ERR(ebufp)) {
                PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
                        "fm_pymt_pol_spec_collect_get_items error", ebufp);
        }

        return;
}
Пример #23
0
/*******************************************************************
 * fm_act_pol_add_event_bal_impacts():
 *******************************************************************/
void
fm_act_pol_add_event_bal_impacts(
    pcm_context_t		*ctxp,
    pin_flist_t		*a_flistp,
    pin_errbuf_t		*ebufp)
{
    pin_cookie_t		cookie = NULL;
    pin_flist_t		*bi_flistp = NULL;
    pin_flist_t		*flistp = NULL;
    pin_flist_t		*bia_flistp = NULL;
    poid_t			*r_pdp = NULL;
    void			*vp = NULL;

    int			impact_type = 0;
    int			count = 0;
    int			rec_id = 0;
    pin_decimal_t 		*dummyp = NULL;

    if (PIN_ERR_IS_ERR(ebufp))
        return;
    PIN_ERR_CLEAR_ERR(ebufp);

    dummyp = pbo_decimal_from_str("0.0", ebufp);
    /***********************************************************
     * Set the balance impact type as pre-rated.
     ***********************************************************/
    impact_type = PIN_IMPACT_TYPE_PRERATED;

    bia_flistp = PIN_FLIST_CREATE(ebufp);

    /***********************************************************
     * Walk the PIN_FLD_TOTALS array in the original event and
     * add a corresponding balance impact arary for that.
     ***********************************************************/
    while ((flistp = PIN_FLIST_ELEM_GET_NEXT(a_flistp, PIN_FLD_TOTAL,
                     &rec_id, 1, &cookie, ebufp)) != (pin_flist_t *)NULL) {

        /***************************************************
         * Add a new element for this balance impact.
         ***************************************************/
        count = (int)PIN_FLIST_ELEM_COUNT(bia_flistp,
                                          PIN_FLD_BAL_IMPACTS, ebufp);
        bi_flistp = PIN_FLIST_ELEM_ADD(bia_flistp,
                                       PIN_FLD_BAL_IMPACTS, count, ebufp);

        /***************************************************
         * Start filling in the standard field values now.
         ***************************************************/
        PIN_FLIST_FLD_SET(bi_flistp, PIN_FLD_IMPACT_TYPE,
                          (void *)&impact_type, ebufp);
        PIN_FLIST_FLD_SET(bi_flistp, PIN_FLD_RESOURCE_ID,
                          (void *)&rec_id, ebufp);
        PIN_FLIST_FLD_SET(bi_flistp, PIN_FLD_TAX_CODE,
                          (void *)"", ebufp);
        PIN_FLIST_FLD_SET(bi_flistp, PIN_FLD_RATE_TAG,
                          (void *)"", ebufp);

        /***************************************************
         * Get and Set the account and item object poids.
         ***************************************************/
        vp = PIN_FLIST_FLD_GET(a_flistp,
                               PIN_FLD_ACCOUNT_OBJ, 0, ebufp);
        PIN_FLIST_FLD_SET(bi_flistp,
                          PIN_FLD_ACCOUNT_OBJ, vp, ebufp);

        vp = PIN_FLIST_FLD_GET(a_flistp,
                               PIN_FLD_ITEM_OBJ, 1, ebufp);
        if (vp) {
            PIN_FLIST_FLD_SET(bi_flistp,
                              PIN_FLD_ITEM_OBJ, vp, ebufp);
        }

        /***************************************************
         * Fill in the dummy rate object poid.
         ***************************************************/
        r_pdp = PIN_POID_CREATE(0, "", 0, ebufp);
        PIN_FLIST_FLD_PUT(bi_flistp, PIN_FLD_RATE_OBJ,
                          (void *)r_pdp, ebufp);

        /***************************************************
         * set the 0 for quantity, discount and percentage
         ***************************************************/
        PIN_FLIST_FLD_SET(bi_flistp, PIN_FLD_DISCOUNT,
                          (void *)dummyp, ebufp);
        PIN_FLIST_FLD_SET(bi_flistp, PIN_FLD_PERCENT,
                          (void *)dummyp, ebufp);
        PIN_FLIST_FLD_SET(bi_flistp, PIN_FLD_QUANTITY,
                          (void *)dummyp, ebufp);

        /***************************************************
         * Set the amount deferred to 0.0
         ***************************************************/
        PIN_FLIST_FLD_SET(bi_flistp, PIN_FLD_AMOUNT_DEFERRED,
                          (void *)dummyp, ebufp);

        /***************************************************
         * Get the amount and set in the bal impact.
         ***************************************************/
        vp = PIN_FLIST_FLD_GET(flistp, PIN_FLD_AMOUNT, 0, ebufp);
        PIN_FLIST_FLD_SET(bi_flistp, PIN_FLD_AMOUNT, vp, ebufp);

    }

    PIN_FLIST_CONCAT(a_flistp, bia_flistp, ebufp);

    PIN_FLIST_DESTROY_EX(&bia_flistp, NULL);
    pbo_decimal_destroy(&dummyp);
    /***********************************************************
     * Error?
     ***********************************************************/
    if (PIN_ERR_IS_ERR(ebufp)) {
        PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
                         "fm_act_pol_add_event_bal_impacts error", ebufp);
    }

    return;
}
Пример #24
0
/*******************************************************************
 * fm_cust_pol_tax_init()
 *
 * Use this policy to load any custom user tax data into an internal 
 * data structure you may have declared in this file. In this default
 * implementation, the structure will be the Tax_Table global flist.
 *
 *******************************************************************/
void 
fm_cust_pol_tax_init(
	pcm_context_t	*ctxp,
	pin_flist_t	*in_flistp,
	pin_flist_t	**out_flistpp,
	pin_errbuf_t	*ebufp)
{
	int32		errp = 0;
	void		*vp = NULL;
	char		*taxfile = NULL;
	FILE		*fp = NULL;
	char		buf[STR_LEN];
	char		code[STR_LEN];
	char		pkg[STR_LEN];
	char		rate[STR_LEN];
	char		start_t[STR_LEN];
	char		end_t[STR_LEN];
	char		j_level[STR_LEN];
	char		j_list[STR_LEN];
	char		descr[STR_LEN];
	char		rule[STR_LEN];
	pin_decimal_t	*pct = NULL;
	pin_decimal_t   *npct=NULL;
	pin_decimal_t   *dpct=NULL;
	int32		len = 0;
	int32		lvl = 0;
	int32		trl = 0;
	int32		elemid = 0;
	int32		precision = 6;
	time_t		startTm = 0;
	time_t		endTm = 0;
	pin_flist_t	*flistp = NULL;

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/* Create the return flist */
	*out_flistpp = PIN_FLIST_CREATE(ebufp);

	/* Set the account POID */
	vp = PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_POID, 0, ebufp);
	PIN_FLIST_FLD_SET(*out_flistpp, PIN_FLD_POID, (void *)vp, ebufp);

	if (Tax_Table == (pin_flist_t*)NULL) {
		/* Create the flist to hold the tax rates */
		Tax_Table = (pin_flist_t*)PIN_FLIST_CREATE(ebufp);
		PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, 
			"Creating the Tax_Table");
	} else {
		/* the tax table has been initialized */
		PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_WARNING, 
			"The Tax_Table has already been created!");
		return;
		/*****/
	}

	/* 
	 * Build Tax_Table from external table, which in this 
	 * implementation happens to be the same taxcodes_map 
	 * file specified in the cm/pin.conf
	 */

	/* get the taxcodes_map path from the pin.conf */
	pin_conf("fm_rate", "taxcodes_map", PIN_FLDT_STR,
		(caddr_t*)&taxfile, &errp);
	if (errp != PIN_ERR_NONE) {
		PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_ERROR, 
			"taxcodes_map table config error!");
		return;
		/*****/
	}

	/* Let's redefine the taxcodes_map table so that the following
	 * columns:
	 *
	 * # Taxcode Pkg  Code1 Code2 Si      Wt_code  Cmdty_code
	 * # ------- ---  ----- ----- ------  -------  ----------
	 *   usage  : Q :  01 :  01 :     S :        :
	 *   VAT    : U : 4.5 :     :       :        :
	 *
	 * will now become these:
	 *
	 * # Taxcode Pkg  Rate  Start      End        Lvl   List    Desc    Rule
	 * # ------- ---- ----  --------   --------   ---   -----   ------  ----
	 *   VAT    : U : 5.0 : 02/01/01 : 01/31/02 : Fed : GB;FR : VAT-EU : Std
	 *   VAT    : U : 4.5 : 02/01/02 : 01/31/08 : Fed : GB    : VAT-GB : Std
	 *   VAT    : U : 4.0 : 02/01/02 : 01/31/08 : Fed : FR    : VAT-FR : Std
	 */

	fp = (FILE*) fopen(taxfile, "r");
	free(taxfile);
	if (fp == (FILE*)NULL) {
		PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_ERROR,
			"Failed to open taxcodes_map file!");
		goto Done;
		/********/
	}

	while (fgets(buf, STR_LEN, fp) != NULL) {

		if (strchr(buf, '#') || *buf == '\n') {
			/* skip comments and blank lines*/
			continue;
		}

		/* Strip newline, if it is there */
		len = strlen(buf);
		if (buf[len-1] == '\n') {
			buf[len-1] = '\0';
		}

		code[0] = pkg[0] = rate[0] = start_t[0] = end_t[0] = '\0';
		j_level[0] = j_list[0] = descr[0] = rule[0] = '\0';

		/* Parse the line in the taxcodes_map */
		fm_cust_pol_parse_map_file(buf, code, pkg, rate,
			start_t, end_t, j_level, j_list, descr, rule);

		if (strncmp(pkg, "U", 1) != 0) {
			/* skip entries other than "user" */
			continue;
			/*******/
		}

		/* Start of validity date */
		fm_cust_pol_str_to_time_t(start_t, &startTm, 0);

		/* End of validity date */
		fm_cust_pol_str_to_time_t(end_t, &endTm, 1);

		/* Jurisdiction level */
		if (strncmp("Federal", j_level, 3) == 0) {
			lvl = PIN_RATE_TAX_JUR_FED;
		} else if (strncmp("State", j_level, 3) == 0) {
			lvl = PIN_RATE_TAX_JUR_STATE;
		} else if (strncmp("County", j_level, 3) == 0) {
			lvl = PIN_RATE_TAX_JUR_COUNTY;
		} else if (strncmp("City", j_level, 3) == 0) {
			lvl = PIN_RATE_TAX_JUR_CITY;
		} else {
			lvl = PIN_RATE_TAX_JUR_FED;
		}

		/* Tax rule (how to tax) */
		if (strncmp(rule, "Std", 3) == 0) {
			trl = 0; /* standard tax */
		} else if (strncmp(rule, "Tax", 3) == 0) {
			trl = 1; /* tax on tax */
		} else if (strncmp(rule, "Fee", 3) == 0) {
			trl = 2; /* flat fee */
		} else if (strncmp(rule, "Inc", 3) == 0) {
			trl = 3; /* inclusive tax */
		} else if (strncmp(rule, "NCS", 3) == 0) {
			trl = 4; /* non-cumulative standard tax */
		} else if (strncmp(rule, "NCT", 3) == 0) {
			trl = 5; /* non-cumulative tax on tax */
		} else if (strncmp(rule, "NCF", 3) == 0) {
			trl = 6; /* non-cumulative flat fee */
		} else if (strncmp(rule, "NCI", 3) == 0) {
			trl = 7; /* non-cumulative inclusive */
		} else {
			trl = 0; /* default */
		}

		/* Tax rate */
		if (trl == 2 || trl == 6) {
			/* 'rate' is a flat fee */
			pct = pbo_decimal_from_str(rate,ebufp);
		} else {
			/* 'rate' is a percentage */
			npct = pbo_decimal_from_str(rate,ebufp);
			dpct = pbo_decimal_from_str("100.0",ebufp); 
			pct = pbo_decimal_divide( npct, dpct ,ebufp);
		}

		/* Set some defaults */
		if (!*j_list) {
			strcpy(j_list, "*");
		}
		if (!*descr) {
			strcpy(descr, "No Tax Description");
		}

		flistp = PIN_FLIST_ELEM_ADD(Tax_Table, PIN_FLD_TAXES, 
			elemid++, ebufp);
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_TAX_CODE, 
			(void*)code, ebufp);
		PIN_FLIST_FLD_PUT(flistp, PIN_FLD_PERCENT,(void*)pbo_decimal_round(pct, 
			(int32)precision,ROUND_HALF_UP,ebufp), ebufp);
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_START_T,
			(void*)&startTm, ebufp);
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_END_T, (void*)&endTm, ebufp);
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE, (void*)&lvl, ebufp);
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_NAME, (void*)j_list, ebufp);
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void*)descr, ebufp);
		PIN_FLIST_FLD_SET(flistp, PIN_FLD_TAX_WHEN, (void*)&trl, ebufp);
		
		pbo_decimal_destroy(&npct);
		pbo_decimal_destroy(&dpct);
		pbo_decimal_destroy(&pct);

	} /* end while */

	fclose(fp);
Done:

	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, 
		"Tax Table from taxcodes_map file", Tax_Table);

	return;
}